The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do you redirect non-www to www prefixed domains??

Discussion in 'General Discussion' started by DReade83, Jan 6, 2008.

  1. DReade83

    DReade83 Well-Known Member

    Joined:
    Oct 20, 2006
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Cheshire, UK
    I've googled this and found a few examples, all of which are the same and work for the people that are trying them (but they don't have cPanel). I've tried it and it doesn't work!

    RewriteCond %{HTTP_HOST} ^mydomain\.co\.uk$ [NC]
    RewriteRule .* http://www.mydomain.co.uk/ [L,R=301]

    Adding this to the httpd.conf file either inside the specific VirtualHost directive or at the bottom of the file, or even inside the site's htaccess file; it doesn't work!

    Can anyone help?

    Surely this should be a feature of cPanel too? Although I've tried to do this using cPanel's redirect function, but I get an error (see http://bugzilla.cpanel.net/show_bug.cgi?id=6250).

    Thanks in advance!
     
  2. hooter814

    hooter814 Member

    Joined:
    Jun 22, 2006
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Sorry I don't have the solution for you as I am having problems as well. Here is what I used for years on a site in an htaccess file which worked perfectly:

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

    Now since moving to a WHM/CPANEL box, those lines will throw a 500 error - all other rewrite rule directives work but as soon as I add those lines, I get a 500 error. This is very standard stuff and as I said worked for years on a domain right up to moving to the cpanel box.

    Thanks in advance for any guidance - perhaps I must use a different server/host environment variable?
     
  3. hooter814

    hooter814 Member

    Joined:
    Jun 22, 2006
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    @DReade and anyone else following along - through trial and error I discovered solution which works for me - it seems cpanel server config does not like the "escaped" for reserved characters in rewrite directive. Here is what I had before which worked on previous servers without issue:

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

    Here is what I changed it to for it to work without throwing 500 Internal Server error on cpanel box:

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

Share This Page