我编写了简单的 .htaccess 并在 Windows Azure 网站上对其进行了测试,但 mod_rewrite 在那里不起作用。为什么?如何重新配置我的 Azure?
重写引擎开启 添加默认字符集utf-8
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test.html$ test.php?%{QUERY_STRING} [L]
最佳答案
Azure 网站无法识别
.htaccess
文件。
Azure 网站在 Microsoft IIS 上运行。
IIS 有一个 URL 重写模块,与 Apache 的 mod_rewrite 非常相似。您可以通过在站点根文件夹中放置一个 web.config
文件来配置 URL 重写规则。
关注Creating Rewrite Rules文章并向下滚动到“查看配置文件中的规则”以了解它的外观。
您定义的规则在 web.config
中将如下所示(并且很可能按预期工作):
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^test.html$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="test.php?{QUERY_STRING}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
关于.htaccess - Azure 中的 Mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17832840/