是否存在.htaccess
可以用来排除子域的变量?
例如,如果域名是www.example.com
,我该如何example.com
在我的.htaccess
文件中使用?
我需要使用变量。我无法硬编码example.com
。
它位于RewriteRule
一个文件中.htaccess
。例如:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\.%{DOMAIN_WITHOUT_SUBDOMAIN}$
RewriteRule ^(.*)$ %{DOMAIN_WITHOUT_SUBDOMAIN}/app/controllers/mobile/index.php [L]
答案1
您基本上已经掌握了诀窍,您可以在其中使用来自的匹配RewriteCond
项RewriteRule
。
因此,要将请求重定向http://subdomain.example.com/something
到http://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]