是否存在排除子域部分的 .htaccess 域变量?

是否存在排除子域部分的 .htaccess 域变量?

是否存在.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

您基本上已经掌握了诀窍,您可以在其中使用来自的匹配RewriteCondRewriteRule

因此,要将请求重定向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]

相关内容