Rank: Member
Joined: 2/3/2007(UTC) Posts: 100
|
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.comwww.domain.com/www.domain.com/Default.aspxwww.domain.com/default.aspxHere'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
|
|
|
|
Rank: Member
Joined: 2/3/2007(UTC) Posts: 100
|
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.aspxwww.mysite.com/Default.aspxredirects 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 :)
|
|
|
|
Rank: Member
Joined: 12/19/2006(UTC) Posts: 153
|
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
|
|
|
|
Rank: Member
Joined: 2/3/2007(UTC) Posts: 100
|
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.
|
|
|
|
Rank: Member
Joined: 12/19/2006(UTC) Posts: 153
|
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.
|
|
|
|
Rank: Member
Joined: 2/3/2007(UTC) Posts: 100
|
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.
|
|
|
|
Rank: Member
Joined: 12/19/2006(UTC) Posts: 153
|
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.
|
|
|
|
Rank: Member
Joined: 2/3/2007(UTC) Posts: 100
|
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.
|
|
|
|
Rank: Member
Joined: 12/19/2006(UTC) Posts: 153
|
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:?"
|
|
|
|
Rank: Administration
Joined: 4/2/2004(UTC) Posts: 2,393 Location: Hummelstown, PA Thanks: 6 times Was thanked: 163 time(s) in 158 post(s)
|
Did you check the form action of the page? My guess is that the form action is default.aspx, so when you post back, it's requesting that URL but the redirect rules are interfering. |
Aaron Sherrick BV Commerce Toll-free 888-665-8637 - Int'l +1 717-220-0012 |
|
|
|
Rank: Member
Joined: 5/14/2005(UTC) Posts: 398
|
to allow post-backs you will have to add another condition for method GET this allows subsequent POST backs to carry on without being rewritten In ISAPI_Rewrite v2 I use: RewriteCond METHOD GET|HEAD I'm sure you guys know the v3 syntax? |
|
|
|
|
Rank: Member
Joined: 12/19/2006(UTC) Posts: 153
|
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]
|
|
|
|
Rank: Member
Joined: 4/10/2009(UTC) Posts: 120 Location: Mechanicsville, VA
Thanks: 3 times Was thanked: 1 time(s) in 1 post(s)
|
|
Tim
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.