| Shopping Cart Software e-Commerce Forums > BV Commerce 5 > BV Commerce 5 Technical Questions > Magic | Forum Quick Jump
|
|  Omer Pro Member
        Date Joined Feb 2007 Total Posts : 100 | Posted 6/3/2010 4:19 PM (GMT -4) |   | Hello everyone,
I'm not gonna post any problem but a simple 301 redirect which will create magic for your site. The only condition is that you need to be using ISAPI_Rewrite 3.0.
Here are your home pages BEFORE 301 Redirect: domain.com domain.com/ domain.com/Default.aspx domain.com/default.aspx www.domain.com www.domain.com/ www.domain.com/Default.aspx www.domain.com/default.aspx
Here's the home page AFTER 301 Redirect: www.domain.com/
Place the following code inside .htaccess at your root
RewriteEngine on
RewriteCond %{HTTPS} (on)? RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC] RewriteCond %{REQUEST_URI} (.+) RewriteRule .? http(?%1s)://www.%2%3 [R=301,L] RewriteRule ^default\.aspx / [NC,R=301,L]
Now all your home pages will be consolidated into 1. This will work magics for you once Google and other bots picks up on it.
Cheers | | Back to Top | | |
 |  Omer Pro Member
        Date Joined Feb 2007 Total Posts : 100 | Posted 6/5/2010 4:53 PM (GMT -4) |   | I just checked the above .htaccess file in a 301 Redirect Checker to see if it's really doing it. It is doing it for the following: www.mysite.com/default.aspx www.mysite.com/Default.aspx redirects both to www.mysite.com/
However it's not doing it for the following (non-www versions): mysite.com/default.aspx mysite.com/Default.aspx Those two redirects to www.mysite.com/default.aspx even though it shows it's redirecting to www.mysite.com/ in the browser address bar.
So I made some changes and it started working for non-www versions as well. Here's the new .htaccess code.
RewriteEngine on RewriteCond %{HTTPS} (on)? RewriteCond %{HTTP:Host} ^(?!www\.)(.+)(default\.aspx)?$ [NC] RewriteCond %{REQUEST_URI} (.+) RewriteRule .? http(?%1s)://www.%2%3/ [R=301,L] RewriteRule ^default\.aspx / [NC,R=301,L]
The only change in the second version is the second RewriteCond... I added (default\.aspx)? at the end, which takes care of the non-www version (mysite.com/default.aspx or mysite.com/Default.aspx)
Any opinions if I'm doing it right or wrong? As far the 301 redirect checking tool shows, it is correct but I'm always suspicious of these kinds of tools :) | | Back to Top | | |
 |  Mark H Pro Member
        Date Joined Dec 2006 Total Posts : 149 | Posted 6/6/2010 12:13 PM (GMT -4) |   | | Just in case you are not already using it, I've found firefox with the free plugins of firebug and Yslow to be very useful for monitoring headers and general site performance, and specifically to verify the route that your 'redirects' are taking. Hope this helps | | Back to Top | | |
 |  Omer Pro Member
        Date Joined Feb 2007 Total Posts : 100 | Posted 6/7/2010 10:50 PM (GMT -4) |   | You are right. Thank you for the tip.
The first version is more sound because %{HTTP:Host} includes Host header value. There should not be any default.aspx. But it works because (default\.aspx)? is not mandatory part. I mean ^(?!www\.)(.+)(default\.aspx)?$ will be matched with mysite.com.
So after my tests, I think the original version I presented is more sound and more practical, which is:
RewriteEngine on RewriteCond %{HTTPS} (on)? RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC] RewriteCond %{REQUEST_URI} (.+) RewriteRule .? http(?%1s)://www.%2%3 [R=301,L] RewriteRule ^default\.aspx$ / [NC,R=301,L]
I just added a $ sign at the end of the last rule. | | Back to Top | | |
 |  Mark H Pro Member
        Date Joined Dec 2006 Total Posts : 149 | Posted 6/8/2010 3:40 PM (GMT -4) |   | Your code seems to cause the default search functionality to fail in firefox. You are redirected to the home page instead of going to search.aspx?...
I'll see if I can mess with it later. | | Back to Top | | |
 |  Omer Pro Member
        Date Joined Feb 2007 Total Posts : 100 | Posted 6/8/2010 5:45 PM (GMT -4) |   | | It might have done it before because of (default\.aspx)? in the end of the HTTP:Host condition. That's why I presented the above code without it to be more sound. It works without a problem. | | Back to Top | | |
 |  Mark H Pro Member
        Date Joined Dec 2006 Total Posts : 149 | Posted 6/8/2010 6:03 PM (GMT -4) |   | By the way, thank you for posting this information. these types of discussions are great for the community.
Sorry, but the following causes the search to fail because of the redirect:
RewriteEngine on RewriteCond %{HTTPS} (on)? RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC] RewriteCond %{REQUEST_URI} (.+) RewriteRule .? http(?%1s)://www.%2%3 [R=301,L] RewriteRule ^default\.aspx$ / [NC,R=301,L]
Given your exact rewrite rule, firebug gives the folowing response on seach 'submit': post default.aspx 301 get www.example.com 200
Without your rule: post default.aspx 302 get search.aspx?keyword=text 200
I've been messing with the code too, and I'll post a solution if I find something. | | Back to Top | | |
 |  Omer Pro Member
        Date Joined Feb 2007 Total Posts : 100 | Posted 6/10/2010 2:11 AM (GMT -4) |   | I'm not sure what might be causing Search to fail with the redirect in your set up because no error is reporting on my site. Search is giving a 200.
It should not give you a 301 redirect unless the button call in search includes default.aspx in the path because that rule(^default\.aspx$) simply tells the server to redirect all requests including default.aspx to the root. Not sure exactly what might be triggering the error on your site. | | Back to Top | | |
 |  Mark H Pro Member
        Date Joined Dec 2006 Total Posts : 149 | Posted 6/10/2010 12:07 PM (GMT -4) |   | I agree, and it is strange. I scoured the source code and could not find any intermediate steps. The code-behind is onclick response.redirect to search.aspx?...
Just to eliminate all factors, on your 'general' settings for your site, in what format do you have "Site Home Page File Name:?" | | Back to Top | | |
   |  Mark H Pro Member
        Date Joined Dec 2006 Total Posts : 149 | Posted 7/30/2010 9:48 PM (GMT -4) |   | OK, so now Omer's 'magic' works perfectly :) Even the search functionality is working with the redirect. Thanks to everyone for piecing together the puzzle.
RewriteEngine on RewriteCond %{HTTPS} (on)? RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC] RewriteCond %{REQUEST_URI} (.+) RewriteRule .? http(?%1s)://www.%2%3 [R=301,L] RewriteCond %{REQUEST_METHOD} GET|HEAD RewriteRule ^default\.aspx$ / [NC,R=301,L] | | Back to Top | | |
 |  TimT Pro Member

       Date Joined Apr 2009 Total Posts : 113 | Posted 8/13/2010 12:10 PM (GMT -4) |   | | | |
| Forum Information | Currently it is Friday, September 10, 2010 12:15 PM (GMT -4) There are a total of 57,412 posts in 12,473 threads. In the last 3 days there were 4 new threads and 38 reply posts. View Active Threads
| | Who's Online | 13 Guest(s), 2 Registered Member(s) are currently online. Details Twist, gdelorey |
Forum powered by dotNetBB 3.0 Alpha dotNetBB © 2000-2010 2003-2009 - BV Software LLC |
|
|