redirecting www.domain.com/home to just www.domain.com

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 3
Joined: 16 Oct 2013, 06:03

redirecting www.domain.com/home to just www.domain.com

16 Oct 2013, 06:21

Hello all

I wonder if you could give me some help.
I've been using .htaccess and mapfiles without problem for years to rewrite urls such as /index.aspx?p=123 to /friendlyname.

However I've hit a stumbling block due to a Google SEO issue. In IIS, http://www.domain.com has a default document of index.aspx?p=3. So when you visit "www.domain.com" you get served index.aspx?p=3 but you don't see that bit of the url.

In the menu if you click the home page you go to http://www.domain.com/home which is also index.aspx?p=3....a duplicate content issue.

Now my suggestion was to correct the menu code so that the homepage link purely links to http://www.domain.com but the boss doesn't want to have to open and recompile several dozen projects and would like to correct it via the .htaccess. The trouble is, whatever I try results in an infinite loop!

I have tried
Code: Select all
#if url contains home just redirect to the pure url
RewriteRule ^(home) http://www.domain.com/? [301,L]
#else carry on with the mapfiles
RewriteRule ^([a-z_0-9]+)$ index.aspx?p=${mapfile:$1} [L]


and

Code: Select all
RewriteCond %{QUERY_STRING} (&|^)p=3(&|$)
RewriteRule ^index.aspx$ http://www.domain.com/? [301,L]


The first one obviously has no effect because it is simply serving the home page and the url remains the same in the location bar.
The second one potentially sets up an infinite loop depending on where I place it amongst the other rules.

Am I overlooking something super simple here? I just want any call to http://www.domain.com/home to actually redirect to http://www.domain.com in the location bar.

Many thanks

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirecting www.domain.com/home to just www.domain.com

16 Oct 2013, 12:00

Well, the simple redirect shouldn't be a problem.

Code: Select all
RewriteEngine on
RewriteBase /

RewriteRule ^home$ http://www.domain.com [NC,R=301,L]


I suspect you want somekind of rewrite behind it. Do you?

Regards
Andrew

User avatar
Posts: 3
Joined: 16 Oct 2013, 06:03

Re: redirecting www.domain.com/home to just www.domain.com

16 Oct 2013, 12:34

Thanks, that seems to have done the trick. I had attempted something almost identical to that before without the [NC, R=301] and nothing happened - although I can see from the example I gave you I accidentally left the $ off the end!
I also used [301,L] without the "R=" which I was unaware of before.
Can you remind me what the NC does?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirecting www.domain.com/home to just www.domain.com

16 Oct 2013, 12:40

NC just means "case non sensitive"

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 18 guests