这是我的.htaccess
文件:
RewriteEngine On
<If "%{HTTP_HOST} == '<myHost>'">
RewriteRule ^$ <url> [R=301,L]
</If>
<Else>
RewriteRule ^$ <another_url> [R=301,L]
</Else>
但它不起作用,看起来像 <If>
语句被忽略。我还从 $_SERVER['HTTP_HOST']
发出了回声在 PHP 中,我得到了我期望的值。另外,RewriteRule
如果我删除 If/Else 语句就可以工作。
我正在将 Azure Webapp 与 Apache/2.4.38 (Debian) 结合使用
最佳答案
在 if
和 else
block 内,您可以使用 RedirectMatch
指令,因为它与它配合使用。 RewriteRule 不起作用,因为它会覆盖 IF/ELSE 并与之冲突。
RewriteEngine On
<If "%{HTTP_HOST} == '<myHost>'">
RedirectMatch 301 ^/$ https://example.com
</If>
<Else>
RedirectMatch ^/$ https://example2.com
</Else>
关于azure - .htaccess If/Else 语句不适用于 HTTP_HOST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68620000/