【问题标题】:.htaccess rewrite folder to subdomain Error.htaccess 将文件夹重写到子域错误
【发布时间】:2015-08-22 21:48:11
【问题描述】:

我有些卡住了。 我是配置 阿帕奇

<VirtualHost *:80>
      ServerAdmin webmaster@example.com
      DocumentRoot /home/abc/Projects/
      ServerAlias *.example.com
      ServerName example.com
      ErrorLog error.log
</VirtualHost>

我的 .htaccess 文件

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [QSA,L]

我的网页返回内部服务器错误

如何配置 .htaccess 接受

更新我的错误日志

[2015 年 8 月 22 日星期六 21:29:58.093791] [core:error] [pid 31081] [client 192.168.83.1:7322] AH00124:由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,使用“LimitInternalRecursion”增加限制。使用'LogLevel debug'获取回溯。,referer:http://test.example.com/

Apache/2.4.10 (Ubuntu) 服务器位于 test.example.com 端口 80

有人知道了

【问题讨论】:

  • “内部错误”的意思是:查看error.log。失败的原因有更具体的原因。 (禁用 mod_rewrite 或 RewriteEngine 或 AllowOverride 等)

标签: php regex apache .htaccess mod-rewrite


【解决方案1】:

您的规则无限循环并最终导致 500 错误。要停止这种情况,您可以使用以下附加条件:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ %1/$1 [L]

%{ENV:REDIRECT_STATUS} 是一个内部 mod_rewrite 变量,在第一次内部重写后设置为 200。

【讨论】:

    猜你喜欢
    • 2014-06-30
    • 2012-11-20
    • 2011-03-02
    • 2017-12-24
    • 2011-10-07
    • 1970-01-01
    • 2019-12-21
    • 2011-08-05
    • 2010-12-28
    相关资源
    最近更新 更多