Welcome to WebmasterWorld Guest from 23.22.182.29

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Force Remove of www causes error

     
8:50 pm on Dec 21, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 17, 2009
posts:41
votes: 0


I am removing the wwww from my domain because it is old and I do not need it. I have tried 40983040909 different examples and it does not work. This one should work, but throws the server into an infinite loop. this is right from a tutorial I have used before

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

I have the server set up as a virtual host with ServerAlias. Is that making it not work?

11:15 pm on Dec 21, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


What kind of 'loop' -- an external redirection loop (multiple browser HTTP redirects and requests), or an internal rewriting loop?

Is there anything in your server error log?

Is UseCanonicalName set to "on" with the "www" hostname declared as the (incorrect) canonical ServerName?

Are there any other RewriteRules or mod_alias directives which may be interfering?

BTW, don't end-anchor the pattern used to check the hostname. Or if you do feel you need to end-anchor it, then follow the ".com" with \.?(:[0-9]+)?$ so that FQDNs and hostnames with appended port numbers won't defeat the rule. Also, escape all literal periods in regex patterns by preceding them with "\":

 RewriteCond %{HTTP_HOST} ^www\.example\.com\.?(:[0-9]+)?$ [NC] 

An alternative, if you don't plan to use subdomains in additional to "www", would be to redirect anything that is *not* exactly the canonical hostname:

 RewriteCond %{HTTP_HOST} !^example\.com$ 

(Note negated pattern, no FQDN or port allowed, no uppercase allowed -- all would get redirected to all-lowercase "example.com")

Jim

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members