cPanel - .htaccess指向子域

时间:2014-01-20 05:37:45

标签: .htaccess zend-framework2 subdomain cpanel document-root

我有2个域名指向相同的托管。

domain_a.com &的 domain_b.com

domain_b.com 实际上指向 domain_a.com 的子域名(即domain_b.domain_a.com)

目录结构

public_html
 |
 |---- domain_a
 |---- domain_b
 |---- ...
 |---- .htaccess

.htaccess的内容是

AddHandler application/x-httpd-php54 .php

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain_a.com$
RewriteCond %{REQUEST_URI} !^/domain_a/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain_a/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain_a.com$
RewriteRule ^(/)?$ domain_a/index.html [L] 

但是,我的 domain_b.com 实际上是在使用ZendFramework 2.哪个文件根目录在public dir

public_html
  |
  |---- domain_a
  |---- domain_b
          |---- public  <------ HERE
  |---- ...
  |---- .htaccess

最后,我得到了这个结果

enter image description here

有什么想法吗?

修改

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?domain_a\.com$
RewriteRule !^domain_a(/|$) /domain_a%{REQUEST_URI} [L,NC]

RewriteCond %{HTTP_HOST} ^(www.)?domain_b\.com$
RewriteRule !^domain_b/public(/|$) /domain_b/public%{REQUEST_URI} [L,NC]

这会导致错误Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

domain_b/public中还有一个.htaccess文件。这是Zend Framework 2

的默认值
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

2 个答案:

答案 0 :(得分:0)

请尝试以下规则:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{HTTP_HOST} ^(www.)?domain_a\.com$
RewriteRule !^domain_a(/|$) /domain_a%{REQUEST_URI} [L,NC]

RewriteCond %{HTTP_HOST} ^(www.)?domain_b\.com$
RewriteRule !^domain_b/public/index\.php(/|$) /domain_b/public/index.php [L,NC]

答案 1 :(得分:0)

通过在子域创建期间将子域的路径设置为domain_b/public/来解决此问题。

enter image description here