Forum Moderators: open

Message Too Old, No Replies

Redirect on IIS Server

         

Gemini23

10:42 pm on May 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,

I need to add a re-write to enable non-www web pages to only show as www pages... on the same website in order to avoid duplicate content:
My hosting prooviders have advised
"You will have to use ISAPI_rewrite to redirect the website from..."

I believe that the code is as follows in a txt file with the file extension .htaccess
but it doesn't work ...

RewriteEngine on
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

Do I also need to add some 'security' measures to this file? (assuming I can get it to work)


Thanks for any advice...
Gemini23

defanjos

2:40 pm on May 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



.htaccess only works in Unix-based servers

You will need isapi_rewrite or similar

dstiles

2:58 am on May 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The hosting provider should have set this up in IIS. I set up sites as www and set up another IIS record to permanently redirect non-www to it.

If they won't do that and they do not have isapi-rewrite ask if they will redirect the 404 handler to a file in your web root - you can trap and redirect there (and do lots of other things).

Finally, add canonical meta redirects into the page headers (see google section of this forum). This won't redirect the page but it should cause SEs to only index one form of the site. A good idea anyway in that respect since it can sort out careless links to the site.

penders

11:45 am on May 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are using a server-side script to create your pages, then you could also do a 301 redirect to the WWW page at the top of your code.

Staffa

12:33 pm on May 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ISAPI_rewrite version 2 uses a file called httpd.ini
ISAPI_rewrite version 3 uses a file called .htaccess as opposed to a file with extension .htaccess

Your host will need to tell you what version is installed on their server.

TheSeoGuy

8:14 pm on May 25, 2010 (gmt 0)

10+ Year Member



Gemini23,

Here is what I did in IIS 6 to have http://domain.com be a permanent 301 redirect to http://www.domain.com
Not sure if this is the best solution, but it seems to work.

Setup the primary site with a host header of www.domain.com.
Point the site to the appropriate folder containing the web site files.

Setup the secondary (redirect) site with a host header of domain.com
On the Home Directory Tab in IIS, Select the "A redirection to a URL" radio option.
Set the Redirect to: text box to the domain to which you are trying to redirect.
In our example, http://www.domain.com

Be sure to check "The exact URL entered above" & "A permanent redirection for this resource"

That should cause domain.com to redirect to www.domain.com.

If you check both domains with a header checker tool such as, [stepforth.com...] everything should check out.

[edited by: marcel at 4:48 am (utc) on May 26, 2010]
[edit reason] delinked example urls [/edit]

serutan

5:02 am on May 26, 2010 (gmt 0)

10+ Year Member



Here's something that might just be crazy enough to work. Normally I don't post stuff I haven't tried myself, but I just now thought of this and don't have time to try it out tonight, and if don't post it now I'll forget about it. So ok, you probably know about using Server.Transfer instead of Response.Redirect. With Response.Redirect the user sees the redirected url. With Server.Transfer the user sees the original url and doesn't know there has been a redirect.

You might be able to put these two effects together to do what you want. In a page in xyz.domain.com you could do a Response.Redirect to an identically named page in www.domain.com. The www page would do nothing but Server.Transfer back to the first page. You would have to add a querystring parameter to the first page to tell it that the transfer has occurred, so it will behave normally instead of doing the Response.Redirect. If this works, the xyz.domain.com page will be served out with the url of the www.domain.com page.