简体   繁体   中英

Remove a part of url with rewrite

I'm not familiarized with this feature and I've found some examples how to do something but I don't know how to set this case:

I want this url http://www.domain.co.uk/anything/en to become http://www.domain.co.uk/anything/

I want to remove the final 'en'

I've tried with:

^/([_0-9a-z-]+)/([_0-9a-z-]+)/en
/{R:1}/{R:2}

or

^http://www.domain.co.uk/([_0-9a-z-]+)/(en)
http://www.domain.co.uk/{R:1}/

But it doesn't work.

You can use the following rule:

<rule name="Remove en" stopProcessing="true">
    <match url="^(.*)/en$" />
    <action type="Rewrite" url="{R:1}" />
</rule>

It will match any url ending with /en and remove this part.
From your example, http://www.domain.co.uk/anything/en will be rewritten as http://www.domain.co.uk/anything

If you want the user to be redirected , then use the following rule:

<rule name="Remove en" stopProcessing="true">
    <match url="^(.*)/en$" />
    <action type="Redirect" url="{R:1}" />
</rule>

The type="Redirect" with no option triggers a permanent(301) redirect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM