• Toll-free  888-665-8637
  • International  +1 717-220-0012
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Omer
#1 Posted : Thursday, June 3, 2010 2:19:22 PM(UTC)
Omer

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.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
Omer
#2 Posted : Saturday, June 5, 2010 2:53:03 PM(UTC)
Omer

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.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 :)
Mark H
#3 Posted : Sunday, June 6, 2010 10:13:39 AM(UTC)
Mark H

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
Omer
#4 Posted : Monday, June 7, 2010 8:50:12 PM(UTC)
Omer

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.
Mark H
#5 Posted : Tuesday, June 8, 2010 1:40:27 PM(UTC)
Mark H

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.
Omer
#6 Posted : Tuesday, June 8, 2010 3:45:53 PM(UTC)
Omer

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.
Mark H
#7 Posted : Tuesday, June 8, 2010 4:03:39 PM(UTC)
Mark H

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.
Omer
#8 Posted : Thursday, June 10, 2010 12:11:27 AM(UTC)
Omer

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.
Mark H
#9 Posted : Thursday, June 10, 2010 10:07:39 AM(UTC)
Mark H

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:?"
Aaron
#10 Posted : Thursday, June 10, 2010 11:20:02 AM(UTC)
Aaron

Rank: Administration

Joined: 4/2/2004(UTC)
Posts: 2,393
United States
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
bbcweb
#11 Posted : Monday, June 28, 2010 3:31:52 PM(UTC)
bbcweb

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?
BetterBuilt.net professional web design and development. call 1-877-325-1109 x7
Mark H
#12 Posted : Friday, July 30, 2010 7:48:34 PM(UTC)
Mark H

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]
ttillman
#13 Posted : Friday, August 13, 2010 10:10:03 AM(UTC)
ttillman

Rank: Member

Joined: 4/10/2009(UTC)
Posts: 120
Location: Mechanicsville, VA

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Like magic... :)


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.

©2024 Develisys. All rights reserved.
  • Toll-free  888-665-8637
  • International  +1 717-220-0012