Есть ли .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]
У вас почти все получилось - хитрость в том, что вы можете использовать совпадения из 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]