我设置了htm / html / php重写&基于此视频的重定向,除了它导致我的php联系表单在提交时中断,它完美地工作。如果没有重写/重定向,表单将被提交,页面被重定向(通过action =“index.php”)到index.php,然后我将其重定向回联系页面(demo.php),通过“header(Location) :demo.php)。一旦我启用重定向/重写页面重定向到“索引”,然后表单永远不会提交,也不会重定向到demo.php。我需要修改哪些设置来解决这个问题?
我的web.config文件中的重写/重定向规则:
<rewrite>
<rules> <rule name="Hide .htm ext">
<match url="^(.*)" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.htm" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.htm" />
</rule>
<rule name="Redirecting .htm ext" stopProcessing="true">
<match url="^(.*).htm" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).htm" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Hide .html ext">
<match url="^(.*)" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.html" />
</rule>
<rule name="Redirecting .html ext" stopProcessing="true">
<match url="^(.*).html" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).html" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Hide .php ext">
<match url="^(.*)" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.php" />
</rule>
<rule name="Redirecting .php ext" stopProcessing="true">
<match url="^(.*).php" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).php" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
</rules>
</rewrite>
通过将pattern =“(。*)。php”改为pattern =“demo.php”使一切正常,虽然它不是一个理想的解决方案,因为它使.php重写/重定向仅适用于一个特定的页面(即demo.php)。