[英]IIS url rewrite rewriting all .asp to .html
I need to create rules for web.config that will rewrite all requests for files with extension .html to .asp and redirect all .asp requests to .html 我需要为web.config创建规则,以将扩展名为.html的文件的所有请求重写为.asp并将所有.asp的请求重定向到.html
Example: 例:
file_xyz.asp rewrites to file_xyz.html file_xyz.asp重写为file_xyz.html
directory1/file_xyz.asp rewrites to directory1/file_xyz.html directory1 / file_xyz.asp重写为directory1 / file_xyz.html
and 和
file_xyz.html redirects to file_xyz.asp file_xyz.html重定向到file_xyz.asp
directory1/file_xyz.html redirects to directory1/file_xyz.asp directory1 / file_xyz.html重定向到directory1 / file_xyz.asp
Thanks in advance 提前致谢
So far this is the syntax I have for the web.config 到目前为止,这是我对web.config的语法
<rule name="RewriteHTMLtoASP" stopProcessing="true">
<match url="^([^/]+)\.html$" />
<conditions logicalGrouping="MatchAll" />
<action type="Rewrite" url="{R:1}.asp" />
</rule>
<rule name="RedirectASPtoHTML" stopProcessing="true">
<match url="^([^/]+)\.asp$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_METHOD}" pattern="^GET$" />
</conditions>
<action type="Redirect" url="{R:1}.html" appendQueryString="false" />
</rule>
Try this, u should know $ tag is the end of redirect/rewrite condition and querystrings will not accepted 尝试此操作,您应该知道$标签是重定向/重写条件的结尾,并且不接受查询字符串
<rule name="RewriteHTMLtoASP" stopProcessing="true">
<match url="(.*).html(.*)" />
<conditions logicalGrouping="MatchAll" />
<action type="Rewrite" url="{R:1}.asp{R:2}" />
</rule>
<rule name="RedirectASPtoHTML" stopProcessing="true">
<match url="(.*).asp(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_METHOD}" pattern="^GET$" />
</conditions>
<action type="Redirect" url="{R:1}.html{R:2}" appendQueryString="true" />
</rule>
Take a look at this article: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx 看一下这篇文章: http : //weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
You can re-write your web pages via web.config settings. 您可以通过web.config设置重新编写网页。 If you use shared hosting I would not recommend to use ISAPI.
如果您使用共享托管,我不建议您使用ISAPI。
Let me know if it works for you. 请让我知道这对你有没有用。
Regards, Anvar 问候,安瓦尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.