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.

Redirect 301

Discussion in 'General Discussion' started by descobrir, Jun 6, 2013.

  1. descobrir

    descobrir Registered

    Joined:
    Jun 5, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I'm facing a problem with the redirect.

    I used the code below and also redirect 301 of the cpanel with wildcard on. It worked but with a problem:

    When the url is 'example.com/anypage.html' I want it to redirect for the same page but with the www. prefix ('www.example.com/anypage'). What is happening is that it redirects always to the homepage of the site ('www.example.com/index.html') instead of the specific page it should have.

    What am I missing?
    Thanks.

    Code used in .htaccess
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    It looks like you essentially want to force the use of the "www" prefix. You could try using an entry such as the following in the .htaccess file:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.example.com$
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
    
    Thank you.
     
  3. descobrir

    descobrir Registered

    Joined:
    Jun 5, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hi!

    I used your entry but the behaviour remains the same.
    If I remove the www. from the url it redirects always to 'http://www.example.com/index.php'


    Thank you for the help.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Are you sure there are no redirects within the script itself that is causing this behavior? Sometimes PHP applications use SEO rules or internal redirects that can conflict with existing redirect rules. Otherwise, you may want to try the Mod_Rewrite forums as there is typically more experienced users with custom Mod_Rewrite rules there:

    Mod_Rewrite Forums

    Thank you.
     
Loading...

Share This Page