Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Oct 2006
    Location
    Cheshire, UK
    Posts
    196

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

    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. #2
    Member
    Join Date
    Jun 2006
    Posts
    8

    Default

    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. #3
    Member
    Join Date
    Jun 2006
    Posts
    8

    Default

    Quote Originally Posted by DReade83 View Post
    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]
    @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]

Similar Threads & Tags
Similar threads

  1. Canonical redirect of www to non www for the same domain
    By Vince778 in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 08-24-2011, 02:22 AM
  2. 302 Redirect of www to non www for the same domain
    By Vince778 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 08-22-2011, 07:01 PM
  3. Redirect without www to www
    By aaronpie in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 06-13-2009, 11:40 AM
  4. non-www to www redirect
    By Underpaid in forum cPanel and WHM Discussions
    Replies: 9
    Last Post: 06-20-2007, 02:20 PM
  5. Redirect www to different ip
    By abusedreality in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-16-2003, 05:41 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube