• Resolved lcf

    (@lcf)


    I moves a client site with multiple WP installations (client.com, client.com/wp1, client.com/wp2) from Linux server to Windows server (IIS).

    Everything works fine, except the permalink.

    I add the following web.config file to client.com/ root directory and it works fine on https://client.com/

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
                <rule name="wordpress" patternSyntax="Wildcard">
                    <match url="*"/>
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                        </conditions>
                    <action type="Rewrite" url="index.php"/>
                </rule></rules>
        </rewrite>
      </system.webServer>
    </configuration>

    With the web.config in root directory, the permalink for WP in subdirectory is wrong, example: https://client.com/wp1/permalink1 is redirect to https://client.com/permalink1

    If I add the same web.config file into subdirectory client.com/wp1, I get Error 500.

    HELP: How to create the correct web.config files for WP in root directory, as well as WP in subdirectory?

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • First, when you add the web.config to a subdirectory, you are probably getting a 500 error because you are trying to add another rewrite rule of the same name. The “wordpress” rewrite rule from the root web.config is inherited by the web.config in the subdirectory, so when IIS sees that you want to define another rule named “wordpress”, it throws an error since it is already defined.

    I would solve this problem by using a <location /> element to define a rule for the subdirectory. Your root web.config would look like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="wordpress" patternSyntax="Wildcard">
              <match url="*"/>
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
              </conditions>
              <action type="Rewrite" url="index.php" redirectType="Found"/>
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
      <location path="wp1">
        <system.webServer>
          <rewrite>
            <rules>
              <remove name="wordpress" />
              <rule name="wordpress" patternSyntax="Wildcard">
                <match url="*"/>
                <conditions>
                  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                </conditions>
                <action type="Rewrite" url="wp1/index.php" redirectType="Found"/>
              </rule>
            </rules>
          </rewrite>
        </system.webServer>
      </location>
    </configuration>

    Note how you are first removing any rewrite rules named “wordpress” in the “wp1” location element, and then redefining the rule to point to the index.php in the subdirectory.

    Another way you could do this, but I think is less desirable because you then have to maintain multiple web.configs, is to simply add the <remove /> element to the web.config you tried in the wp1 subdirectory. This would have the same effect. It may be the more ideal solution in your situation if you need to apply other settings via web.config in that subdirectory, but I would still recommend using the location element in the root web.config.

    Disclaimer: I have not been able to test this myself, but I am fairly certain it should help solve your problem.

    Edit: I forgot to mention that I added redirectType="Found" to the action elements. The default redirect type is Temporary, which is inappropriate for these permalinks since they are not temporary. The Permanent redirect type is also inappropriate because it tells the browser/client to never use the original URL again, but we want them to continue to use the permalink. Thus, Found is the best type to be used for permalinks.

    • This reply was modified 8 years, 4 months ago by Blair Allen.

    Just wanted to thank you for saving me a LOT of time, @blallen1. That worked perfectly. Much appreciated.

    I just log in to say thanks. The problem tortured me for days. Great appreciation.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘IIS permalink conflict with WP in subdirectory’ is closed to new replies.