The issue is how to do two things: force SSL on all requests, and redirect the domain to the public_html/somefolder - where the site/domain content lives. The recommendation from the hosting place (BlueHost, although I have seen this elsewhere, is to do this second thing via htaccess in the public_html folder:
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
#this next section is what the hosting place says to use
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/somefolder.c/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /somefolder.c/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ somefolder.c/index.php [R,L]
Note that the site content lives in the somefolder.c folder.
So the htaccess should take care of these requests
www.example.com
example.com
http://example.com
https://example.com
http://www.example.com
https://www.example.com
https://www.example.com/somepage.php #this page is in public_html/somefolder.c
http://example.com/folderb/somepage.php #this page is in public_html/somefolder.c/folderb
...and variations therein.
I'm not sure that the htaccess above will work in all of those situations. So:
Is there a better way?
Is there a requirement for a separate htaccess in the
somefolder.c
folder (the content 'root')? If so, what should it contain?
I'd prefer not to rearrange the whole place (moving the site files from public_html/somefolder.c
to the public_html
folder.
Added
There are several domains associated with this hosting account. The primary domain is www.example.com
.
I note that the 'first force SSL part' is working. And the intent of the second part is to have https://www.example.com
point to the somefolder.c
content, with https://www.example.com/folderb/somepage.php
point to the public_html/somefolder.c/folderb/somepage.php
file.
That https://www.example.com/folderb/somepage.php
request will (sometimes; not consistently) show https://www.example.com/somefolder.c/folderb/somepage.php
on the address bar. I want the https://www.example.com/folderb/somepage.php
to show on the address bar. So the 'somefolder.c
' should never appear on the address bar.
- how best to do this with htaccess files in the public_html folder
- are additional htaccess files needed in subfolders?
/somefolder.c
should be entirely hidden from the user? So, to the end user it just looks like all the files are served from the document root? It's just that you have a mixture of internal rewrites and external redirects to this subdirectory - which I suspect is incorrect. Are you hosting more than one domain on this account? Presumably you don't yet have any other.htaccess
files? Do you need to be able to serve any files from the document root?