Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect from non-www to www

Using httpd.conf

         

wfernley

2:53 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was curious if anyone could help figure out this 301 redirect from a non-www to www. For example domain.com will redirect to www.domain.com.

All my rewrites are using httpd.conf and not .htaccess.

Can anyone help?

Thanks in advance!

Wes

jdMorgan

4:03 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only difference is that in httpd.conf, the RewriteRule pattern would start with "^/"

Jim

wfernley

5:32 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you for the reply.

How would you start a domain?

This is my Rewrite Condition:

# Redirect non-www to www
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) [domain.com...] [R=301,L]

IT does not seem to work though.

jdMorgan

7:09 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Setup
RewriteEngine on
# Redirect non-www to www
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]

Flush your browser cache after making any changes to the code.

Jim

wfernley

7:26 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks again Jim,

For some reason this aint workin.

I tried also clearing my cache.

If you want I can sticky you my rewrites and you can take a look. Let me know if thats possible.

Thanks again!

jdMorgan

7:56 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll have to be sure that the code is invoked for requests to the non-www domain; That is, the code cannot be inside any containers specific to the www domain or it won't ever be invoked for non-www requests.

Jim