Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Sorry for the vague title, the problem is too complex to summarize in a short phrase...

I'm trying to set up the following redirection rules:

  1. blog.mydomain.net/en/something: redirected to www.mydomain.com/something
  2. blog.mydomain.net/fr/something: redirected to www.mydomain.fr/something
  3. blog.mydomain.net/*: redirected to www.mydomain.com

Rule 3 is working, but rules 1 and 2 seem to be skipped so rule 3 is always applied. Here are my web.config rules:

<!-- Canonicalize mydomain.com to www.mydomain.com -->
<rule name="CanonicalHostNameRule_en" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^mydomain\.com$" />
    </conditions>
    <action type="Redirect" url="http://www.mydomain.com/{R:1}" />
</rule>

<!-- Canonicalize mydomain.fr to www.mydomain.fr -->
<rule name="CanonicalHostNameRule_fr" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^mydomain\.fr$" />
    </conditions>
    <action type="Redirect" url="http://www.mydomain.fr/{R:1}" />
</rule>

<!-- Redirect blog.mydomain.net/en/something to www.mydomain.com/something -->
<rule name="RedirectBlog_en" enabled="true" stopProcessing="true">
    <match url="^/en(/.*)?$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^blog\.mydomain\.net$" />
    </conditions>
    <action type="Redirect" url="http://www.mydomain.com/{R:1}" />
</rule>
<!-- Redirect blog.mydomain.net/fr/something to www.mydomain.fr/something -->
<rule name="RedirectBlog_fr" enabled="true" stopProcessing="true">
    <match url="^/fr(/.*)?$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^blog\.mydomain\.net$" />
    </conditions>
    <action type="Redirect" url="http://www.mydomain.fr/{R:1}" />
</rule>

<!-- Redirect blog.mydomain.net/* to www.mydomain.com -->
<rule name="RedirectBlog_other" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^blog\.mydomain\.net$" />
    </conditions>
    <action type="Redirect" url="http://www.mydomain.com/" />
</rule>

<!-- Wordpress-specific rules -->
...

I don't understand why rules RedirectBlog_en and RedirectBlog_fr are skipped; I tested the regular expressions and they work fine.

Can anyone spot the problem?


EDIT: if I disable the 3rd rule (RedirectBlog_other), then rules 1 and 2 work fine... how is it possible, since rules 1 and 2 are executed before rule 3?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

OK, I got it!

First, things weren't happening as I thought; rules 1 and 2 were not working when I disabled rule 3: I was still redirected to my actual domain, but this was done by Wordpress, not by my rules.

Second, my pattern for matching the URL was wrong: the leading '/' is not included in the input, so my rules weren't matching at all.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.