【问题标题】:cPanel - .htaccess point to subdomaincPanel - .htaccess 指向子域
【发布时间】:2014-02-09 04:54:29
【问题描述】:

我有 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

最后,我得到了这个结果

有什么想法吗?

编辑

# 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]

【问题讨论】:

  • 问题是什么?显示两个域的 VirtualHost 条目。
  • 这是共享主机,我不认为我可以更改虚拟主机。基本上我希望我的domain_b.com 指向public_html/domain_b/public
  • 我不想让你改变我只是想看看这些条目来了解你的设置。
  • ok 在下面发布了答案。

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


【解决方案1】:

试试这些规则:

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]

【讨论】:

  • 现在我收到 500 内部服务器错误。我找不到虚拟主机配置文件。
  • 你能检查一下你的 Apache error.log 是因为这个 500 的原因吗
  • [alert] [client xxx.xxx.xxx.xxx] /home/user/public_html/.htaccess: RewriteCond: bad flag delimiters
  • 这意味着您在复制/粘贴此答案时犯了一些错字。如果您在上面看到,我什至没有在RewriteCond 中使用任何标志。您需要确保 .htaccess 的 RewriteCond 行中没有杂散空间。
  • 是的,你是对的。现在我得到了这个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.
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2015-10-09
    • 2011-10-13
    • 2013-12-24
    • 2011-08-05
    • 2019-01-19
    • 2013-11-22
    • 2014-02-25
    • 2010-12-07
    • 1970-01-01
    相关资源
    最近更新 更多