简体   繁体   中英

IIS web.config redirect subfolder to domain

I have a strange problem with IIS url_rewrite module and web.config setup. I think there is a problem with the matching pattern or I'm doing something completely wrong..

My setup is a ASP.Net MVC app with multi language support. For starters I have three languages enabled, English, German and French.. so you could access them with a language parameter www.domain.com/en/ www.domain.com/de/ www.domain.com/fr/.. now I bought a german domain and setup up the german part of the page to .de domain, so now I have www.domain.com/en/ www.domain.de/de/ www.domain.com/fr/ everything ok so far..

The problem i'm trying to figure out how to add a safe 301 redirect if you write www.domain.com/de/ to www.domain.de/de/ or vice versa www.domain.de/en/ back to www.domain.com/en/ ... the main reason i wan't to solve this its because of SEO to fix the duplicate content issues ..

I have IIS 8.5, url_rewrite module installed and now I'm stuck with this in the in my web.config

<rule name="DE Redirect" stopProcessing="true">
    <match url="(.*)" ignoreCase="true" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^www\.domain\.com\/de\/$" />
    </conditions>
    <action type="Redirect" url="https://www.domain.de/de/{R:0}" redirectType="Permanent" />
</rule>

I want to redirect the user if they enter or get to www.domain.com/de/page1 to www.domain.de/de/page1 and only if there is the www.domain.com/de/ in the url, I won't redirect if they enter to english of french language website.

Any idea what am I doing wrong or what is the best way to debug such redirects.. I have tried with the Failed Request Tracing but didn't found anything helpful.

Any ideas? Cheers

Because answers cannot contain domain.com, then I will use everywhere example.com and example.de

You should use redirect like that:

<rule name="DE Redirect" stopProcessing="true">
   <match url="^de/(.*)" ignoreCase="true" />
   <conditions>
       <add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
   </conditions>
   <action type="Redirect" url="https://www.example.de/de/{R:1}" redirectType="Permanent" />
</rule>

Also if you want to prevent opening the French language on German domain https://www.example.de/fr and redirect it to https://www.example.com/fr then you should also add

<rule name="FR Redirect on DE domain" stopProcessing="true">
   <match url="^fr/(.*)" ignoreCase="true" />
   <conditions>
       <add input="{HTTP_HOST}" pattern="^www\.example\.de$" />
   </conditions>
   <action type="Redirect" url="https://www.example.com/fr/{R:1}" redirectType="Permanent" />
</rule>

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