IIS7 重写模块 - 从根目录重定向到 default.aspx
我遇到一种情况,需要从根重写为default.aspx。因此,如果有人点击 www.domain.com 或 www.domain.com/ 我需要重定向到 www.domain.com/default.aspx - 知道这个正则表达式是什么样子以及正则表达式使用哪个服务器变量吗?
当我运行跟踪并访问 www.domain.com/ 或 www.domain.com 时,它总是显示 SCRIPT_NAME 和其他类似的服务器变量的值为 /default.aspx - 但这在重写模块中不起作用。例如,当有人访问 www.domain.com/ 或 www.domain.com 时,SCRIPT_NAME 仍然是 /default.aspx - 因此它似乎不会发现他们访问了非 default.aspx 页面。
I have a situation where I need to rewrite from the root to default.aspx. So if someone hits www.domain.com or www.domain.com/ I need to redirect to www.domain.com/default.aspx - any idea what the regex for this looks like and which server variable to regex on?
When I run a trace and I visit www.domain.com/ or www.domain.com it always shows the SCRIPT_NAME and other similar server variables to have a value of /default.aspx - however this does not work in the rewrite module. E.g. when someone visits www.domain.com/ or www.domain.com the SCRIPT_NAME is still /default.aspx - so it doesn't seem to pick up that they visited the non default.aspx page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过使用 URL 重写映射(重写模块的一部分)解决了这个问题,我能够从 / 重定向到 /default.aspx。作为重写映射之前的规则,我确保所有请求都重定向到结尾斜杠。
I solved this by using a Url Rewrite map (part of the rewrite module), I was able to redirect from / to /default.aspx. As a rule before the rewrite map I make sure that all requests are redirected to an ending slash.
我遇到了类似的问题,我认为 IIS 向您隐藏 URL 并且只提供您已经知道的脚本名称,这真的很糟糕。在早期版本的 IIS 中情况更糟,因为它忘记复制查询字符串。我必须通过根本不定义任何默认文档来解决这个问题,并使目录列表的错误页面拒绝重定向到脚本。我想同样的事情在这里也会起作用。
I had a similar problem and I think it really sucks that IIS hides the URL from you and only gives you the name of the script, which you already know. It was worse in earlier versions of IIS, because it forgot to copy the query string. I had to work around that by not defining any default document at all, and making the error page for directory listing denied redirect to the script. I guess the same thing would work here.