MVC3 .net 4.0 无扩展名 url 和 isapi_rewrite
不幸的是,我被迫为我的 MVC 网站使用 IIS6。 .net 4.0 添加了模仿愚蠢的 hack 的功能,使无扩展名的 url 在 IIS6 中工作。我的网站旨在利用 url 重写来实现 SEO 目的。客户端希望使用的关键字 url 决定了精心设计的 url 重写方案。
微软实施该功能的问题实际上归结为 url 重写和尝试匹配模式。我见过各种规则试图从 url 中删除可怕的 eurl.axd ,以便模式匹配。我尝试使用这些规则
RewriteRule ^(.)/eurl.axd/[a-f0-9]{32}(.)$ $1$2 或者 RewriteRule (.)eurl.axd/. $1
确实有效,但在存在嵌套重定向时也会引入其他问题。即,将旧网址处理为新网址等,
会发生 eurl.axd 被删除并且在重定向时 isapi_filter 未收到导致 IIS 404 错误的请求。
通过修改网址,我想出了这个可能的解决方案。
RewriteRule ^generators/generator-parallel-capability/([^/])/([^/])$ /generators/htmlcontent/generator-parallel-capability/$1/$2 [NC,L]
它只是抓取 eurl.axd 部分并将其重写到附加的执行 url 中。
有更好的办法吗?我有数百个符合此模式的网址,如果有一个规则可以处理所有这些网址,那就太好了。
Unfortunatly I am forced to use IIS6 for my MVC website. .net 4.0 adds functionality to mimic the stupid hack for getting extensionless urls to work in IIS6. My website is designed to take advantage url rewriting for SEO purposes. The keyword urls that the client wishes to use dictate an elaborate url rewriting scheme.
The problems with Microsofts impelmentation of the feature really comes down to url rewriting and the attempt to match a pattern. I have seen various rules that attempt to strip the dreaded eurl.axd from the url so that the patterns will match. I attempted to use these rules
RewriteRule ^(.)/eurl.axd/[a-f0-9]{32}(.)$ $1$2
or
RewriteRule (.)eurl.axd/. $1
which does work but it also introduces other problems when there are nested redirects. i.e. handling old urls to new ones, etc
what happens is the eurl.axd gets stripped and on the redirect the isapi_filter doesnt get the request which results in an IIS 404 errror.
Tinkering around with the urls, i came up with this possible solution.
RewriteRule ^generators/generator-parallel-capability/([^/])/([^/])$ /generators/htmlcontent/generator-parallel-capability/$1/$2 [NC,L]
it just grabs the eurl.axd portion and rewrites it to the executing url with it appended.
Is there a better way? I have several hundred urls that meet this pattern and it would be nice to have a single rule handle them all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们在配置之上使用了一个通用规则来删除 /eurl.axd234234
RewriteRule ^(.)/eurl.axd.$ $1 [NC]
这必须适用于除根之外的所有内容。
We used one generic rule on top of the config to cut the /eurl.axd234234
RewriteRule ^(.)/eurl.axd.$ $1 [NC]
this must work for everything but the root.
当 url 被重写多次时,使用重写规则
RewriteRule ^(.)/eurl.axd.$ $1 [NC]
会导致一些令人不快的行为。即从旧的 url 到新的虚荣 url,然后到实际的执行 url。使用地图,我能够生成一个非常有效的模式,并且可以防止 .htaccess 文件混乱。
第一个检测模式
/controller/some-content/eurl.axd/1234
并将其重写为/controller/some-controller-action/eurl.axd/1234
第二个做同样的事情,只是最后没有 eurl 垃圾。这是针对我运行 iis 7 的开发机器的,
我确信有更好的方法,并且我当然愿意接受更好的建议。
Using the rewrite rule
RewriteRule ^(.)/eurl.axd.$ $1 [NC]
results in some unplesant behavior when the url is rewritten more than one time. i.e. from an old url to the new vanity url then to the actual execution url.Using maps, I was able to produce a pattern that works quite nicely and keeps the .htaccess file from being cluttered.
The first detects the pattern
/controller/some-content/eurl.axd/1234
and rewrites it to/controller/some-controller-action/eurl.axd/1234
the second does the same thing just without the eurl junk at the end. this is for my dev machine running iis 7
Im sure there are better ways and I am certainly open to better suggestions.