I'm not strong in .htaccess and for this reason I need your help.
Recently I purchased wildcard SSL certificate and changing http to https doesn't work properly.
The site is build on CakePHP 2.3 and public_html
directory has a following structure:
/app
/lib
/plugins
/Cake
/sub1.domain.com
- app
- lib
- plugins
- ...
/sub2.domain.com
- app
- lib
- plugins
- ...
It is how my hosting handle subdomains.
Folder Cake
is a shared CakePHP core across all subdomains + main domain.
When SSL was installed, in cPanel was automatically added record *.domain.com -> /public_html
that I can't change.
Everything works fine when I use http, but https redirect all my subdomains on main domain.
.htaccess in /public_html
looks like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# http|https www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^(.*)$ http%1://domain.com/$1 [R=301,L]
# redirect all subdomains
RewriteCond %{HTTP_HOST} !^domain\.(.*)$ [NC]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ /%{HTTP_HOST}/$1 [NC,L,NS]
RewriteCond %{HTTP_HOST} ^domain\.(.*)$ [NC]
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{HTTP_HOST} ^domain\.(.*)$ [NC]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
All .htaccess files in subdomains are default CakePHP files with RewriteBase /
Did someone had similar situation and how did you solve it? Please help as it really outside of my knowledge.
Update #4
/public_html/sub1.domain.com/.htaccess
is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteRule ^$ sub1.domain.com/app/webroot/ [L]
RewriteCond %{HTTPS} =on
RewriteRule (.*) sub1.domain.com/app/webroot/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Everything looks ok, only https://sub1.domain.com redirects to https://sub1.domain.com/sub1.domain.com and all generated paths are includes /sub1.domain.com
How can I remove folder sub1.domain.com from URL and from links?
Should I update Configure::write('App.baseUrl', env('SCRIPT_NAME'));
on something else?
Still trying to fix it