Forum Moderators: phranque

Message Too Old, No Replies

re-write doesn't work - help?

         

Gemini23

7:04 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 avoide 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

jdMorgan

7:18 pm on May 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First things first...

Because your host mentioned ISAPI Rewrite, are you hosted on an Apache server, or an IIS server?

Jim

Gemini23

8:07 pm on May 2, 2010 (gmt 0)

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



Hi jd,

Not sure exactly where to look.. it is a Windows Server... and it has IIS Application Pool within the control panel... it is a shared hosting...

I believe that the server is: Microsoft-IIS/6.0

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



Well, I claim no expertise in IIS or ISAPI Rewrite, but this is how you could code that for an Apache server running mod_rewrite:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://www.example.com/$1 [R=301,L]

This redirects all non-blank non-canonical hostname requests to the canonical hostname, preserving the original http/https protocol.

I have no idea whether it will work on ISAPI Rewrite, or how it might need to be changed to do so.

Be aware that we do have a Microsoft IIS forum [webmasterworld.com] as well.

Jim

g1smd

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

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



See also: [webmasterworld.com...]