简体   繁体   中英

IIS 7.5 WinServer 2008 R2 URL Rewrite Module for multiple domains and multilingual paths

I am attempting to utilize (per the title) the IIS URL Rewrite Module to redirect some old domains to new domains. I've looked through a lot of MS Tech articles and various blogs and, for our situation, I think I have an idea of the solution required, however, my redirects aren't firing and I am only getting a 404 error instead of redirects to pages.


Details: We currently have a multilingual site set up like domain. com / English/Path/To/Page and domain. de / English/Path/To/Page , domain. fr / English/Path/To/Page . Our CMS - Kentico - is setup such that these translate per the top level domain name. We are now migrating to a new site and we want domain. com / English/Path/To/Page and domain. de / German/Translated/Path/To/Page and domain. fr / French/Translated/Path/To/Page . I believe the following is the correct way to setup the 'rewriteMaps':

<rewrite>
    <rewriteMaps>
      <rewriteMap name="USRedirects" defaultValue="">
          <add key="/OLD/PATH/" value="/NEW/PATH/ENGLISH" />
          <add key="/OLD/PATH/" value="/NEW/PATH/ENGLISH" />
          <add key="/OLD/PATH/" value="/NEW/PATH/ENGLISH" />
       </rewriteMap>
    </rewriteMaps>
</rewrite>
<rewrite>
    <rewriteMaps>
      <rewriteMap name="DERedirects" defaultValue="">
          <add key="/OLD/PATH/" value="/NEW/PATH/GERMAN" />
          <add key="/OLD/PATH/" value="/NEW/PATH/GERMAN" />
          <add key="/OLD/PATH/" value="/NEW/PATH/GERMAN" />
       </rewriteMap>
    </rewriteMaps>
</rewrite>

Note: the 'old paths' are all the same and all in English. only the domains (.de, .com, .fr) denote the difference. Going forward, the new site has translated URLs in each language. I then have the following setup as my rules section:

<rules>
    <rule name="US Redirects" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" /> <!-- rule back reference is captured here  -->
    <conditions>
        <add input="{USRedirects:{HTTP_HOST}}" pattern="^www.domain.com$" /> <!-- condition back-reference is captured here -->
    </conditions>
    <action type="Redirect" url="http://www.domain.com/{R:1}" redirectType="Permanent" /> <!-- rewrite actions uses back-references to condition and to rule when rewriting the URL -->
     </rule>
   </rules>

<rules>
    <rule name="DERedirects" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" /> <!-- rule back reference is captured here  -->
    <conditions>
        <add input="{USRedirects:{HTTP_HOST}}" pattern="^www.domain.de$" /> <!-- condition back-reference is captured here -->
    </conditions>
    <action type="Redirect" url="http://www.domain.de/{R:1}" redirectType="Permanent" /> <!-- rewrite actions uses back-references to condition and to rule when rewriting the URL -->
     </rule>
   </rules>

In the end, I want a set of rules named for each language/domain (DE=domain.de, US=domain.com, FR=domain.fr, etc. and each one of those will correspond to the appropriate rewriteMaps (named DERedirects, USRedirects, FRRedirects, etc.) using the reference syntax in the input value {:{HTTP_HOST}}.

After all is said and done (and quite a few missteps with syntax which ended in 500 errors of course) this doesn't crash or 500 on me but the only thing it does is throw a 404 and say the page that I want redirected does not exist.

Any help would be GREATLY appreciated. And, if there's any further information I am leaving out that would be important, please let me know and I will do what I can to provide more detail.

Here are a couple of the references I've been using:

http://ruslany.net/2010/05/storing-url-rewrite-mappings-in-a-separate-file/

https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

http://weblogs.asp.net/owscott/iis-url-rewrite-redirect-multiple-domain-names-to-one

Thanks!

small UPDATE: The above sections are only partials of the overall configuration. I need many more than just DE and COM setups.

Also, the Ruslany article I TRIED to implement but received too many 500 errors in getting it setup. Something with syntax or setup wasn't working correctly so I am putting all the maps and rules directly into the web.config file (while keeping it under 250kb per the rquirement).

Found my answer! Just had to figure out/realize that "{:{HTTP_POST}}" as the input was not possible to do then I could search correctly. Found this post:

http://forums.iis.net/t/1177509.aspx

and, in case that disappears from the interwebs, here is the copy/pasted version:


Hi,

The input of request url in rewrite module doesn't contain host name. So you need to use {HTTP_HOST} to verify it. You can update your rules as following to make them work:

<rewrite>
  <rewriteMaps>
    <rewriteMap name="Site1Redirects">
      <add key="/mypage" value="/EN/mypage.aspx" />
    </rewriteMap>
    <rewriteMap name="Site2Redirects">
      <add key="/mypage" value="/CY/mypage2.aspx" />
    </rewriteMap>
  </rewriteMaps>
  <globalRules>
    <rule name="Redirect rule1 for Site 1" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^site1.mysite.com$" />
        <add input="{Site1Redirects:{REQUEST_URI}}" pattern="(.+)" />
      </conditions>
      <action type="Redirect" url="{C:0}" appendQueryString="false" />
    </rule>
    <rule name="Redirect rule1 for Site 2" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^site2.mysite.com$" />
        <add input="{Site2Redirects:{REQUEST_URI}}" pattern="(.+)" />
      </conditions>
      <action type="Redirect" url="{C:0}" appendQueryString="false" />
    </rule>
  </globalRules>
</rewrite>

Thanks.


That is all ...

UPDATE: just because I found this as further, valuable information:

https://moz.com/blog/what-every-seo-should-know-about-iis#chaining

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