web.config:隐藏文件扩展名并强制在 url 末尾添加斜线
web.config: hide file extension and force to add trailing slash at end of url
我坚持要在 webconfig 中重写和重定向规则。
我想 删除文件扩展名并在 URL 末尾强行添加斜杠它带我到 404 页。
仅供参考 - http://example.com/about-us.php/ 工作正常
预期结果 - http://example.com/about-us/ 重定向到 404 页面。
请告诉我使用 web.config 文件隐藏文件扩展名并同时添加尾部斜线的代码。
我应用了下面列出的一些规则,添加了尾部斜线,但当我输入 put [ 时它会将我带到 http://example.com/about-us.php/ =37=]http://example.com/about-us 在浏览器中
仅供参考 - 它与 http://example.com/about-us/ 一起工作正常,但我想要 http://example.com/about-us URL 到 http://example.com/about-us/
这是我的规则列表:
<system.webServer>
<httpErrors errorMode="Custom"><!-- For non-managed files -->
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.php" responseMode="ExecuteURL" />
</httpErrors>
<rewrite>
<rules>
<rule name="Add trailing slash rule 1" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}.php/" />
</rule>
<rule name="Add trailing slash rule 2" stopProcessing="true">
<match url="(.*[^/])" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php/" redirectType="Permanent" />
</rule>
<rule name="hide php extension" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.php/" />
</rule>
</rules>
</rewrite>
</system.webServer>
您需要使用此规则:
<rules>
<rule name="AddTrailingSlashRule" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" />
</rule>
<rule name="hide php extension" stopProcessing="true">
<match url="^(.*)/$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="^(.*)([^/])$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="(.*?)\.[a-zA-Z]{1,4}$" negate="true" />
</conditions>
<action type="Redirect" url="{R:0}/" redirectType="Permanent" />
</rule>
IIS 用户规则:添加/添加到所有 URL。为所有 seo
工作
我坚持要在 webconfig 中重写和重定向规则。 我想 删除文件扩展名并在 URL 末尾强行添加斜杠它带我到 404 页。 仅供参考 - http://example.com/about-us.php/ 工作正常
预期结果 - http://example.com/about-us/ 重定向到 404 页面。
请告诉我使用 web.config 文件隐藏文件扩展名并同时添加尾部斜线的代码。
我应用了下面列出的一些规则,添加了尾部斜线,但当我输入 put [ 时它会将我带到 http://example.com/about-us.php/ =37=]http://example.com/about-us 在浏览器中
仅供参考 - 它与 http://example.com/about-us/ 一起工作正常,但我想要 http://example.com/about-us URL 到 http://example.com/about-us/
这是我的规则列表:
<system.webServer>
<httpErrors errorMode="Custom"><!-- For non-managed files -->
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.php" responseMode="ExecuteURL" />
</httpErrors>
<rewrite>
<rules>
<rule name="Add trailing slash rule 1" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}.php/" />
</rule>
<rule name="Add trailing slash rule 2" stopProcessing="true">
<match url="(.*[^/])" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php/" redirectType="Permanent" />
</rule>
<rule name="hide php extension" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.php/" />
</rule>
</rules>
</rewrite>
</system.webServer>
您需要使用此规则:
<rules>
<rule name="AddTrailingSlashRule" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" />
</rule>
<rule name="hide php extension" stopProcessing="true">
<match url="^(.*)/$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="^(.*)([^/])$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="(.*?)\.[a-zA-Z]{1,4}$" negate="true" />
</conditions>
<action type="Redirect" url="{R:0}/" redirectType="Permanent" />
</rule>
IIS 用户规则:添加/添加到所有 URL。为所有 seo
工作