Replace IIS7 URL Rewriter

I really like the IIS7 URL rewriter module and so far it worked fine for me.

There is one thing I don’t know how to do about: I would like to redirect all URLs that encoded spaces (% 20) to the URL where spaces are replaced by dashes (-) forever.

So this is:

http://www.test.com/About%20Our%20Mission.aspx

should redirect to this:

http://www.test.com/About-Our-Mission.aspx

Is this possible with just regular expressions?

+3
source share
4 answers

There is no way to do exactly what you want.

You can agree to 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}
+6
source

.aspx , URL- . -. Global.asax:

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

IIS7 web.config URL- .aspx:

<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"/>
        <!-- ... -->

URL- IIS7 , , ...

+2

ISAPI_Rewrite 3 Helicon Ape %20s:

RewriteBase /
RewriteRule ^(.*)%20(.*)$ $1-$2 [LP,R=301,L]
+1

You can write a Custom Rewrite Provider to perform any manipulation of the source URL. But this is not only due to regular expression. More details here .

+1
source

Source: https://habr.com/ru/post/1711492/


All Articles