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!

Redirecting domain to folder with SSL

Discussion in 'Security' started by ljj3, Dec 7, 2017.

  1. ljj3

    ljj3 Active Member

    Joined:
    Nov 7, 2014
    Messages:
    29
    Likes Received:
    3
    Trophy Points:
    3
    cPanel Access Level:
    Reseller Owner
    One of my accounts located at yourdomain.com is a Wordpress site which resides in folder "subfolder" which is in public_html.

    I used this htaccess code located in public_html to successfully reach the site:

    Code:
    # .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.
    RewriteCond %{HTTP_HOST} ^([URL='http://www.)?yourmaindomain.com$']www.)?yourmaindomain.com$[/URL]
    # Change 'subfolder' to be the folder you will use for your main domain.
    RewriteCond %{REQUEST_URI} !^/subfolder/
    # Don't change this line.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Change 'subfolder' to be the folder you will use for your main domain.
    RewriteRule ^(.*)$ /subfolder/$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.)?yourmaindomain.com$']www.)?yourmaindomain.com$[/URL]
    RewriteRule ^(/)?$ subfolder/index.php [L]
    
    What I notice is:

    - access from https:// and https://www work correctly
    - access from http:// and http://www result in a double redirect which is very slow
    - I suspect the slowness is caused by firing up Wordpress in some way


    I've searched around and have not found a htacess snippet which does the job efficiently.

    Any clues?

    Thanks!

    /ljj
     
    #1 ljj3, Dec 7, 2017
    Last edited by a moderator: Dec 7, 2017
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,711
    Likes Received:
    1,794
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    You may want to consider updating the document root for the domain name to match the path to the subdirectory as opposed to using Mod_Rewrite for this purpose. We document how to do this at:

    AutoSSL & different DocumentRoot

    Note that without root access, your hosting provider may need to perform this action on your behalf. Otherwise, consider moving the WordPress installation over to the public_html directory:

    Moving WordPress « WordPress Codex

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

    ljj3 Active Member

    Joined:
    Nov 7, 2014
    Messages:
    29
    Likes Received:
    3
    Trophy Points:
    3
    cPanel Access Level:
    Reseller Owner
    Yep, moving the site up to public_html seems like the right move. It was a site we took over from someone else, should have fixed it then.
     
    #3 ljj3, Dec 8, 2017
    Last edited by a moderator: Dec 8, 2017
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