Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Redirect domains

Discussion in 'General Discussion' started by Flegy, May 3, 2018.

Tags:
  1. Flegy

    Flegy Member

    Joined:
    Sep 7, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Croatia
    cPanel Access Level:
    DataCenter Provider
    Hello,

    How can I redirect example.com/hosting to example-hosting.com ?

    tried using htaccess and redirect option on cpanel, is the only way to redirect with PHP code or have htaccess script to do 301 redirect?
     
    #1 Flegy, May 3, 2018
    Last edited by a moderator: May 3, 2018
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,714
    Likes Received:
    1,883
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello @Flegy,

    Can you verify what happens when you setup the redirect from within cPanel using the Redirects option? Do any existing redirect rules exist in the .htaccess file in the document root of that website? Note that if you are looking for a custom Mod_Rewrite rule to try, here's a link to a StackOverflow thread with an example:

    How to redirect subdirectory to new domain with masking?

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Flegy

    Flegy Member

    Joined:
    Sep 7, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Croatia
    cPanel Access Level:
    DataCenter Provider
    Sorry for slow reply. example.com is main domain and it redirect to subfolder. So now when I enter example.com/anyothersubfolder it open another web.

    public_html .htaccess

    Code:
    #AddDefaultCharset On
    #AddDefaultCharset UTF-8
    # .htaccess main domain to subfolder redirect
    # Copy and paste the following code into the .htaccess file
    # in the public_html folder of your hosting account
    # make the changes to the file according to the instructions.
    
    # Do not change this line.
    RewriteEngine on
    
    # Change yourdomain.com to be your main domain.
    
    # Change 'subfolder' to be the folder you will use for your main domain.
    
    # Don't change this line.
    
    # Change 'subfolder' to be the folder you will use for your main domain.
    
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ 'https://www.domain.tld/$1' [R=301,L]
    RewriteCond %{http_host} ^domain.tld [NC]
    RewriteRule ^(.*)$'https://www.domain.tld/$1' [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^('http://www.)?domain.tld$'
    RewriteCond %{REQUEST_URI} !^/panel/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^(.*)$ /panel/$1
    
    # Change yourdomain.com to be your main domain again.
    # Change 'subfolder' to be the folder you will use for your main domain
    # followed by / then the main file for your site, index.php, index.html, etc.
    
    RewriteCond %{HTTP_HOST} ^([URL='http://www.)?domain.tld$']www.)?domain.tld$[/URL]
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^(/)?$ panel/index.php [L]
    
     
    #3 Flegy, May 9, 2018
    Last edited by a moderator: May 9, 2018
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,714
    Likes Received:
    1,883
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello @Flegy,

    Is it setup that way on purpose? If so, is there any reason you prefer to use a redirect instead of simply uploading the website contents to the public_html directory itself?

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Flegy

    Flegy Member

    Joined:
    Sep 7, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Croatia
    cPanel Access Level:
    DataCenter Provider
    I have many webs and want to have all organized. Its hard when having a lot of folders what use the main web, so like to have all separated.
     

    Attached Files:

  6. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,714
    Likes Received:
    1,883
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello @Flegy,

    Do you have root access to this server? If so, you can use the following steps to modify the default document root for the domain name utilized as the primary domain name of the account:

    1. Update the "documentroot" value to the new path in the following files:

    /var/cpanel/userdata/username/domain.tld
    /var/cpanel/userdata/username/domain.tld_SSL

    2. Remove the existing cache files:

    Code:
    rm /var/cpanel/userdata/username/domain.tld.cache
    rm /var/cpanel/userdata/username/domain.tld_SSL.cache
    3. Rebuild the cache files and the Apache configuration file:

    Code:
    /scripts/updateuserdatacache
    /scripts/rebuildhttpdconf
    4. Restart Apache:

    Code:
    /scripts/restartsrv_httpd
    This would allow you to point the domain name to the correct document root without using a redirect.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice