Forum Moderators: phranque

Message Too Old, No Replies

Redirecting from www.site.com to site.com

Getting rid of the 'www'

         

Scooter24

9:33 am on Oct 18, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'd like to redirect all requests to [site.com...] to [site.com...] (and not do any redirects for direct requests to [site.com...] ).

How can this be achieved, i.e. what is the correct syntax of the .htaccess Apache directives?

bill

2:27 am on Oct 19, 2004 (gmt 0)

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



Here's one way:

RewriteEngine On 
RewriteCond %{HTTP_HOST}!^example\.com
RewriteRule ^.*$ http://example.com%{REQUEST_URI} [R=301,L]

jdMorgan

4:15 am on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Some previous discussion [webmasterworld.com].

Jim

Scooter24

9:22 pm on Oct 19, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I tried what was suggested:

RewriteEngine On
RewriteCond %{HTTP_HOST}!^example\.com
RewriteRule ^.*$ [example.com%{REQUEST_URI}...] [R=301,L]

replacing example and com with my domain and got 500 Internal Server Error. Perhaps something is wrong with the syntax?

Scooter24

9:27 pm on Oct 19, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Could it be that the forum software is removing some spaces?

Scooter24

9:35 pm on Oct 19, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Never mind - problem solved. There has to be a space between {HTTP_HOST} and!^example\.com

Why does the forum software remove spaces?

BTW, while I write this, the forum software just removed the space between the "and" and the exclamation sign... Even if I insert it again the software keeps taking it out. Perhaps you should fix this bug.

jdMorgan

9:51 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It just does that. Use two spaces to override it !

Jim

Scooter24

9:08 am on Oct 20, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



It's a bug, Jim. Not everybody might be aware of this two spaces rule, but people sometimes post Apache directives and the automatic space removal makes them invalid. It is something that should be fixed.