通配符子域和CakePHP [英] Wildcard subdomains and CakePHP
问题描述
我不强的.htaccess基于这个原因,我需要你的帮助。
最近我购买了通配符SSL证书和改变HTTP到HTTPS不能正常工作。
该网站是建立在CakePHP的2.3和的public_html
目录下有一个结构如下:
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
- ...
这是怎么我的主机手柄的子域。
文件夹蛋糕
在所有子域名+主域共享CakePHP的核心。
It is how my hosting handle subdomains.
Folder Cake
is a shared CakePHP core across all subdomains + main domain.
在安装SSL,在cPanel的自动添加记录 * domain.com - > /的public_html
,我不能改变。
When SSL was installed, in cPanel was automatically added record *.domain.com -> /public_html
that I can't change.
一切正常,当我使用HTTP,HTTPS,但重定向我所有的子域的主域名。
在的.htaccess /的public_html
是这样的:
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>
在所有子域的.htaccess文件是默认的CakePHP文件的RewriteBase /
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.
更新#4
/public_html/sub1.domain.com/.htaccess
是:
<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>
一切看起来正常,只有 https://sub1.domain.com 重定向到的 https://sub1.domain.com/sub1.domain.com 和所有生成的路径包括/sub1.domain.com
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
我如何从URL,并从链接中删除文件夹sub1.domain.com?
How can I remove folder sub1.domain.com from URL and from links?
我应该更新配置::写(App.baseUrl,ENV('SCRIPT_NAME'));
得也快?
还是试图修复它
Should I update Configure::write('App.baseUrl', env('SCRIPT_NAME'));
on something else?
Still trying to fix it
推荐答案
1周(其它任务之间)之后,我终于解决了这个!
Finally after 1 week (between other tasks) I solved this!
下面是我的解决办法:
/public_html/.htaccess
<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>
/public_html/sub1.domain.com/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/%{HTTP_HOST}
RewriteRule ^%{HTTP_HOST}(.*)$ /$1
RewriteCond %{HTTPS} on
RewriteRule ^$ %{HTTP_HOST}/app/webroot/ [L]
RewriteCond %{HTTPS} on
RewriteRule (.*) %{HTTP_HOST}/app/webroot/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/public_html/sub1.domain.com/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/public_html/sub1.domain.com/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ %{HTTP_HOST}/index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
最后最重要的!
And finally the most important!
/public_html/sub1.domain.com/app/webroot/index.php
在底部: $调度=新调度();
更改为: $调度=新调度('');
这篇关于通配符子域和CakePHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!