WordPress Permalinks in a redirected subfolder

Discussion in 'Third-party applications' started by Cameron Vetter, Oct 29, 2015.

  1. I'm trying out winhost in hopes of migrating a bunch of my sites to it. I learned the hard way that my account does not support multiple sites, but eventually found an article explaining how to set things up using URL rewriting. I ended up creating a few folders and putting my sites in them:

    cameronvetter.com
    zecil.com

    I'm using the following rule to make www.cameronvetter.com work in /web.config:

    <rule name="www.cameronvetter.com" >
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^www.cameronvetter\.com$" />
    </conditions>
    <action type="Rewrite" url="\cameronvetter.com\{R:0}" />
    </rule>

    This seems to work just fine, however permalinks are broken. After doing some forums reading I found some advice on to address this and created the file cameronvetter.com/web.config with this rule:


    <rule name="WordPressRewriteRule">
    <match url=".*" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="cameronvetter.com/index.php" logRewrittenUrl="true" />
    </rule>

    I've tried every conceivable combination of these rules including putting them both in /web.config and have had no luck. I suspect the advice I read on the forum that is 4 years old, is no longer right for IIS 8 but I'm not having any luck finding anything wrong with it. Any help would be great, I like a lot about winhost, just the difficulty of the rewriting url's is keeping me from starting to switch over DNS's and diving in completely.
     
  2. FredC

    FredC Winhost Staff

    Let me make sure I understand. You want to use multiple domains on a single wordPress installation.

    Or do you want to send request to 2 separate WordPress installation based on the URL?
     
  3. I want to send the request to 2 separate WordPress installation based on the URL.
     
  4. Ok, I can't believe that nobody on here is running WordPress with pretty permalinks... Or is this an impossible scenario with this type of shared hosting?
     
  5. ComputerMan

    ComputerMan Winhost Staff

  6. I've now changed it to match the exact code from this article. (This is functionally the same as what wordpress itself adds to your web.config for you if you let it.) The rule is not even executing. It executes my rewrite at the root level and that is it. Here are my exact current web.config files, I've changed them a bit since my original post adding content.

    \web.config

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <directoryBrowse enabled="false" />
            <rewrite>
                <rules>
                    <clear />
                    <rule name="Rewrite scrapbook.cameronvetter.com" enabled="true" stopProcessing="false">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^scrapbook.cameronvetter\.com$" />
                            <add input="{PATH_INFO}" pattern="^/scrapbook.cameronvetter.com($|/)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\scrapbook.cameronvetter.com\{R:0}" />
                    </rule>
                   <rule name="Rewrite cameronvetter.com" enabled="true" stopProcessing="false">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^(www\.)?cameronvetter\.com$" />
                            <add input="{PATH_INFO}" pattern="^/cameronvetter.com($|/)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\cameronvetter.com\{R:0}" />
                    </rule>
    
                                    <rule name="Rewrite zecil.com" enabled="true" stopProcessing="false">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^(www\.)?zecil\.com$" />
                            <add input="{PATH_INFO}" pattern="^/zecil.com($|/)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\zecil.com\{R:0}" />
                    </rule>
                    <rule name="Rewrite iridiumdefense.net" enabled="true" stopProcessing="false">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^(www\.)?iridiumdefense\.net$" />
                            <add input="{PATH_INFO}" pattern="^/iridiumdefense.net($|/)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\iridiumdefense.net\{R:0}" />
                    </rule>
                </rules>
            </rewrite>
            <urlCompression doStaticCompression="true" doDynamicCompression="true" />
        </system.webServer>
    </configuration>
    /cameronvetter.com/web.config:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
            <rules>
                <rule name="Main Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <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>
        <urlCompression doStaticCompression="false" doDynamicCompression="false" />
      </system.webServer>
    </configuration>
    
    It seems like this should work, I'm perplexed that it doesn't...
     
  7. FredC

    FredC Winhost Staff

    hmm.. let me talk to our dev guy and see
     
  8. Did some tests and the way I got it to work is by adding the permalink rewrite rule in the root web.config after the domain rewrite rule. In the permalink rewrite rule, you still have to check for host name since you are dealing with multiple domains.

    For example:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <clear />
            <rule name="Rewrite domain.com" stopProcessing="false">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_HOST}" pattern="^(www\.)?domain\.com$" />
                <add input="{PATH_INFO}" pattern="^/domain.com($|/)" negate="true" />
              </conditions>
              <action type="Rewrite" url="\domain.com\{R:0}" />
            </rule>
            <rule name="Rewrite domain.com permalink" stopProcessing="true">
              <match url="(.*)"/>
              <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_HOST}" pattern="^(www\.)?domain\.com$" />
                <add input="{PATH_INFO}" pattern="^/domain.com($|/)" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
              </conditions>
              <action type="Rewrite" url="\domain.com\index.php"/>
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    
     
    Michael likes this.
  9. That is definitely the spirit of what I am trying to do. The problem with this approach is that while it fixes permalinks it breaks static files in the web space. So pictures, javascript, stylesheets do not display. This is supposed to be resolved by these lines in the second rule:

    <code>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
    </code>

    But the {REQUEST_FILENAME} does not actually match the file in the file system so the condition is not met. For example on my site right now every page uses the file:

    http://www.cameronvetter.com/wp-content/themes/great-child/style.css

    Because the REQUEST_FILENAME is E:\web\cameronv\wp-content\themes\great-child/style.css and the actual file is at E:\web\cameronv\cameronvetter.com\wp-content\themes\great-child/style.css it ends up getting transformed by this rull resulting in it trying to load E:\web\cameronv\cameronvetter.com\index.php\wp-content\themes\great-child/style.css.
     

  10. The first rule is supposed to take care of the static content and should not get caught by the second rule. The second rule is only for the permalinks.

    In your Wordpress General settings, what do you have set for the the WordPress Address and Site Address URLs? For cameronvetter.com as an example, it should be,

    WordPress Address (URL): http://cameronvetter.com/cameronvetter.com
    Site Address (URL): http://cameronvetter.com
     
    Cameron Vetter and Michael like this.
  11. Yes, you nailed it, that was the problem. I was not fully understanding the difference between WordPress address and sit address in WordPress... Thanks for the help!
     
  12. For everyone else out there that may read this thread, the solution to have multiple wordpress sites hosted in folders and have permalinks is two steps:

    at \web.config create all of your redirects. If you have www.site1.com and www.site2.com in folders site1folder and site2folder your web config would look like this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
        <configuration>
            <system.webServer>
                <directoryBrowse enabled="false" />
                <rewrite>
                    <rules>
                        <clear />
                        <rule name="Rewrite www.site1.com" stopProcessing="false">
                            <match url="(.*)" />
                            <conditions logicalGrouping="MatchAll">
                                <add input="{HTTP_HOST}" pattern="^(www\.)?site1\.com$" />
                                <add input="{PATH_INFO}" pattern="^/site1folder($|/)" negate="true" />
                            </conditions>
                            <action type="Rewrite" url="\site1folder\{R:0}" />
                        </rule>
                        <rule name="Rewrite site1.com permalink" stopProcessing="true">
                            <match url="(.*)" />
                            <conditions logicalGrouping="MatchAll">
                                <add input="{HTTP_HOST}" pattern="^(www\.)?site1\.com$" />
                                <add input="{PATH_INFO}" pattern="^/site1.com($|/)" negate="true" />
                                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                            </conditions>
                            <action type="Rewrite" url="\site1folder\index.php" />
                        </rule>
    
                        <rule name="Rewrite www.site2.com" stopProcessing="false">
                            <match url="(.*)" />
                            <conditions logicalGrouping="MatchAll">
                                <add input="{HTTP_HOST}" pattern="^(www\.)?site2\.com$" />
                                <add input="{PATH_INFO}" pattern="^/site2folder($|/)" negate="true" />
                            </conditions>
                            <action type="Rewrite" url="\site2folder\{R:0}" />
                        </rule>
                        <rule name="Rewrite site2.com permalink" stopProcessing="true">
                            <match url="(.*)" />
                            <conditions logicalGrouping="MatchAll">
                                <add input="{HTTP_HOST}" pattern="^(www\.)?site2\.com$" />
                                <add input="{PATH_INFO}" pattern="^/site2.com($|/)" negate="true" />
                                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                            </conditions>
                            <action type="Rewrite" url="\site2folder\index.php" />
                        </rule>
                    </rules>
                </rewrite>
                <urlCompression doStaticCompression="true" doDynamicCompression="true" />
            </system.webServer>
        </configuration>
    
    Then for each web site in the wordpress control panel set the site to have a wordpress url of the full folder, so for site1.com the urls would be:

    WordPress Address (URL): http://site1.com/site1folder
    Site Address (URL): http://site1.com

    Hope that helps everyone else!
     
    ComputerMan, Michael and Elshadriel like this.
  13. Thanks for summarizing Cameron, I'm quite sure this is going to help others.
     

Share This Page