URL Rewriter and IIS configuration

Suppose you want to use http://XXX/aa-bb  as your displayed url, but you want to remove the extension from your URL and the actual URL is http://XXX/aa-bb.aspx. You can write some codes by yourself to implement URL Rewriting feature.

 

But there is a problem. The code only works on dev box. when hosted in production I keep getting 404s error when requesting http://XXX/aa-bb, only http://XXX/aa-bb.aspx can work.

 

So you got to do some configuration in IIS to solve this problem. Dont't forget that mapping "*all*" requests to asp.net. Here is how-to:

 

In IIS6, go to home directory tab, click "configuration" and "add a wildcard map to the following file ".

browse to "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll" and enter .*

ensure that 'check that file exists' is unchecked.

 

But everything has two sides. It will slow down the performance more or less. secondly, by unchecking "check that file exists" will bring about another problem you will experience. You can not utilize the Error 404 ability provided by IIS to catch error 404 'file not found' to redirect your request to a page you specify.

 

There is another way to implement URL rewriter. You can use error 404 ability to get the request like "http://XXX/aa-bb" in the aspx page you specify in IIS and then transfer this page to the phisical page you want. But the head status in response for this aspx page will be changed to 404 and the header might be rewrited, which will cause some problems when your websites are required to do SEO since some websites spiders and crawers will ignore error 404 and stop processing this page. Secondly, the css or js defined in the header might reference to wrong link path. I ran into this problem. But actually I don't know exactly what happened inside.

 

There is one tiny thing we need to notice. When you implement URL rewriter, Suppose you have a displayed URL, Let's say  http://XXX/newview/Military", and you want to rewrite it to http://XXX/newview.aspx?Title=Military.

As you can see here, the directory path level is decreased from 2 to 1. So when you use css link like "../css/global.css" you cannot find the css file. So you need to use Resolve("~/Css/global.css") method provided by asp.net.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值