IIS7 URL Rewriting Module Replace

前端 未结 5 657
再見小時候
再見小時候 2020-12-07 03:33

I really like the IIS7 URL rewriting module and so far, it worked great for me.

There is one thing that I\'m not sure how to do: I would like to permanently redirec

相关标签:
5条回答
  • 2020-12-07 03:51

    The same may be achieved in one rule with ISAPI_Rewrite 3 or Helicon Ape for any number of %20s:

    RewriteBase /
    RewriteRule ^(.*)%20(.*)$ $1-$2 [LP,R=301,L]
    
    0 讨论(0)
  • 2020-12-07 03:58

    Perhaps I'm mad, but this seems to work...

    Use a URL_Rewrite rule using Regular Expressions with this pattern:

    ^(.*) (.*)
    

    Redirect to

    {R:1}-{R:2}
    

    I've tested this with a single space or many spaces and it works fine for me using IIS 10. Note that it works just as well for %20 as it does for "" in the URL string, cheers.

    0 讨论(0)
  • 2020-12-07 04:01

    One of then nice things about .aspx is how easy it is to rewrite URLs with real code. Just add a little search and replace code to your web site's Global.asax file:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        string path = HttpContext.Current.Request.Path;
        // Search and replace, RegEx, etc.
        HttpContext.Current.RewritePath(path);
    }
    

    On IIS7, you have to add some entries in web.config to handle rewriting non .aspx URLs:

    <system.webServer>
        <handlers>
            <clear/>
            <add name="Brands1" path="Brands/*.html" verb="*" type="ASP.global_asax" resourceType="Unspecified"/>
            <add name="Brands2" path="Brands/\?*.html" verb="*" type="ASP.global_asax" resourceType="Unspecified"/>
            <!-- ... -->
    

    The IIS7 URL rewriting module is great, but just because you have a hammer...

    0 讨论(0)
  • 2020-12-07 04:02

    There's no way to do directly what you want.

    You might settle for something like this:

    ^(.*)%20(.*)%20(.*)%20(.*)  replaced by:  {R:1}-{R:2}-{R:3}-{R:4}
    ^(.*)%20(.*)%20(.*)         replaced by:  {R:1}-{R:2}-{R:3}
    ^(.*)%20(.*)                replaced by:  {R:1}-{R:2}
    
    0 讨论(0)
  • 2020-12-07 04:12

    You can write Custom Rewrite Provider to do any manipulation you want with the original url. But that involves more than regular expression only. More details here.

    0 讨论(0)
提交回复
热议问题