我在Azure上创建了一些PHP应用程序,但这是我第一次将IIS用于我的PHP应用程序。我知道如何在Apache上使用.htaccess进行url重写并且没有问题。但是如何在Azure IIS上实现这一点。这是我的.htaccess for Apache。
的.htaccess
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
答案 0 :(得分:1)
您需要使用您的Web.config文件并使用此中的<system.webServer>
和<rewrite>
规则。
您需要在web.config
内使用以下内容从.htaccess
复制上面的代码:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
答案 1 :(得分:1)
正确 web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="Default.aspx" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="ModX IIS7 Rule 1 (By Simon Fraser)" stopProcessing="true">
<match url=".*" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_USER_AGENT}" pattern="^.*internal\ dummy\ connection.*$" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="ModX IIS7 Rule 2 (By Simon Fraser)" stopProcessing="true">
<match url="^(manager|assets)" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="ModX IIS7 Rule 3 (By Simon Fraser)" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>