开发者

How to rewrite url containing plus and special chracters?

We've got some incoming URLs that needs to be redirected, but we are having trouble with URLs that contains pluses (+).

For example any incoming URL must be redirected to the Homepage of the new site:

/eng/news/2005+01+01.htm

Should be redirected to to the home pa开发者_如何学运维ge of the new site

/en/

Using UrlRewriter.net we've set up a rule which works with 'normal' URLs but does not work for the above

<redirect url="~/eng/(.+)" to="/en/index.aspx" />

However it works fine if i change the incoming URL to

/eng/news/2005-01-01.htm

What's the problem and can anyone help?


I don't know about UrlRewriter.net, and I'm not sure which regex syntax it uses. I give some hint based on Perl regex.

  1. what is the ~ at the beginning? Perhaps you mean ^, i.e. beginning of the string.
  2. (.+) matches any character repeated one or more time; it does not match the + sign as you want

This is one way to write a (Perl) regex matching URLs starting with the string /eng/ and containg a + sign:

^\/eng\/.*\+.*

I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜