如何在 ISAPI_Rewrite 中重定向页面
我使用 ISAPI_Rewrite v2 并且我有这个规则:
RewriteRule ^/cnvrt$ /convert [I,RP]
RewriteRule ^/convert$ /convert.aspx [I,L]
我希望每当有人输入 site.com/cnvrt 时,它都会将他重定向到 site.com/convert
上述规则的问题在于它只是放置了一个窗口显示该页面可以在此 url 下找到:... 我想要的是将他重定向到页面(网址将更改),
我不想在代码级别处理它。
我该怎么做?
谢谢
I use ISAPI_Rewrite v2 and I have this rules:
RewriteRule ^/cnvrt$ /convert [I,RP]
RewriteRule ^/convert$ /convert.aspx [I,L]
I want that whenever someone enter site.com/cnvrt it will redirect him to site.com/convert
The problem with the above rule is that it just put a window that says the page can be found under this url: ....
And what I want is to it redirect him to the page(that the url will change)
I dont want to handle it in the code level.
How can I do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个很好的方案,将旧的重写 url 作为 301 重定向永久重定向到新的 url,然后将该新 url 重写到页面。
尝试这些 v3 规则:
您使用的是什么版本:v2 还是 v3?
有趣的是,我在 v3 下尝试了你的 v2 规则,它们按照你说的做了,重写但不重定向。我认为原因是第一条规则将 /cnvrt 重写为 /convert,但 RP 不是重定向语法。没有重定向,最后也没有 L,因此它会进入下一个规则,该规则将 /convert 重写为 /convert.aspx 页面。
This is a good scenario, redirecting an old rewrite url to a new one permanently as a 301 redirect, then rewriting that new url to the page.
Try these v3 rules:
What version are you using: v2 or v3?
Interestingly, I tried your v2 rules under v3, and they did just what you said, rewriting but not redirecting. I think the reason is that the first rule rewrites /cnvrt to /convert, but RP isn't the redirect syntax. There's no redirect and no L for last, so it falls through to the next rule, which rewrites /convert to /convert.aspx page.
[I,RP] 用于 ISAPI_Rewrite 2
[NC,R=301] 用于 ISAPI_Rewirte 3
[I,RP] are used in ISAPI_Rewrite 2
[NC,R=301] are for ISAPI_Rewirte 3