Welcome to WebmasterWorld Guest from 54.146.194.42

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

non-www to www redirecting infinitely

     
7:33 pm on Sep 22, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Aug 8, 2003
posts: 232
votes: 0


Can anyone tell me why the following is redirecting infinitely? I have placed this in my httpd.conf in a Directory section:

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

[edited by: jdMorgan at 7:40 pm (utc) on Sep. 22, 2007]
[edit reason] example.com [/edit]

7:50 pm on Sept 22, 2007 (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


I don't see anything catastrophically wrong with that, but be aware that RewriteRule patterns in code for httpd.conf differ slightly from that used in .htaccess. Specifically, the URL-path matched by RewriteRule patterns in .htaccess will be stripped of the leading slash, whereas this leading slash will be present in the URL-path seen by RewriteRule in http.conf.

So, this code should be modified slightly in either of the following ways:


RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule [b]^/(.*)$[/b] http://www.example.com/$1 [R=301,L]

-or-

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.co[b]m$1[/b] [R=301,L]

I removed the [NC] from the RewriteCond patterns as well; It will simplify many of your other rules if you enforce not only the canonical domain name "spelling," but specifically the all-lowercase canonical domain name.

If either version of the modified code does not help, and if www.example.com is not the primary ServerName (with example.com as the ServerAlias), then make sure your server is configured with UseCanonicalName off.

Jim

2:10 am on Sept 23, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Aug 8, 2003
posts: 232
votes: 0


Great, thanks for the help. After implementing the redirect in the way you mentioned I was still having trouble. It turns out that part of my PHP code was causing the infinite redirect.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members