是否有一个排除子域部分的.htaccess域variables?

是否有一个.htaccessvariables我可以使用排除子域?

例如,如果域名是www.example.com ,那么我如何在我的.htaccess文件中使用example.com

我需要使用一个variables。 我不能硬编码example.com

你几乎已经知道了 – 诀窍是你可以在你的RewriteRule使用RewriteCond中的匹配。

因此,要将请求redirect到http://subdomain.example.com/somethinghttp://example.com/script.php

 # We'll capture the last two period-separated sections # (as well as ensure that at least 3 sections were in the requested hostname) RewriteCond %{HTTP_HOST} \.([^\.]\.[^\.])$ # Now we can use that captured section (the last two parts of the name) with %1: RewriteRule ^.*$ http://%1/script.php [R=301,L]