Forum Moderators: phranque

Message Too Old, No Replies

http://domain.com to http://www.domain.com

Unable to properly redirect to "www" via 301

         

kindred1

7:49 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Hello,
We are having a CDN service installed on our server and are having a problem setting up the 301 redirect on our linux/cpanel server.

Can anyone suggest a htaccess code that should work?

The whole idea is that no end-users will be browsing our site without 'www', if they leave out the 'www' they will hit our origin server and will be redirected to
[mydomain.com...] , which will be cached and served over the CDN.

[mydomain.com...] -> 301 [mydomain.com...]

kindred1

11:31 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



If you want to preserve the page the user asked for instead of redirecting all requests to the home page, you'll need to back-reference the page name in the rule using $1:

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

Jim

[edited by: jdMorgan at 1:14 am (utc) on Sep. 23, 2005]
[edit reason] Sorry, edited post instead of answering it. [/edit]