homepage Welcome to WebmasterWorld Guest from 54.243.13.30
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Force Remove of www causes error
chasehx




msg:4047206
 8:50 pm on Dec 21, 2009 (gmt 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?

 

jdMorgan




msg:4047290
 11:15 pm on Dec 21, 2009 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved