基于%{HTTP_HOST}的htaccess内部重写

时间:2014-08-24 14:02:33

标签: regex apache .htaccess mod-rewrite rewrite

当主机名是子域名时,目标是在服务器上的某个位置内部重写所有请求到文档(* .domain.de,如www.domain.de,a.domain.de)

非工作(状态500).htaccess条件/规则如下所示:

RewriteCond %{HTTP_HOST} ^(.*).domain\.de$ [NC]
RewriteRule ^(.*)$ /info\.html [L]

也许这是一个无限循环问题,因为它要求" info.html"可能再次检查htaccess规则? (甚至内部重写?)

1 个答案:

答案 0 :(得分:0)

事情是,一旦你重写为/info.html,你需要停止进一步的重写,否则500内部服务器将由于无限循环而引起。

你的规则如下:

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.de$ [NC]
RewriteRule !^info\.html$ /info.html [L]

否定条件!^info\.html$将在写入一次后停止进一步重写。