Redirecting domain to folder with SSL

ljj3

Active Member
Nov 7, 2014
42
4
58
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
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,243
463
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.
 

ljj3

Active Member
Nov 7, 2014
42
4
58
cPanel Access Level
Reseller Owner
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.
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.
 
Last edited by a moderator: