Wordpress in Subdirectory

Discussion in 'Site Programming, Development and Design' started by Dave Fuller, Dec 6, 2019.

  1. Hi,

    I am trying to install multiple Wordpress sites in subdirectories. Currently, I have used the domain pointer and the web.config and it is resolving the domain and the domain/wp-admin correctly. Everything works great there. However, when I try to access a page or post, I get a 404 error, but not even a Wordpress 404 error, I get an IIS 404 error. So, if I try to go to www.mydomain.com/page I get the 404 error.

    I've tried a rewrite rule in the subdirectory to rewrite to index.php (as per the Wordpress instructions) - example - and have tried a clear command at the beginning of the rewrite but none of that works. Always the same result. Any recommendations? This should be possible.

    Thank you,
  2. ComputerMan

    ComputerMan Winhost Staff

    What Permalinks option are you using for the Wordpress site in the subdirectory?

    In your root web.config file. Do you only have rules to do the redirection? Do you also have rules for the Wordpress sites?
  3. I have PostName selected but when I try to change it, nothing happens. I have the rules to do the redirection in the main and I have tried the rules for the Wordpress sites in both the main directory (with proper selection logic) and in the subdirectory. In the subdirectory, it doesn't action it, so currently, I have it as rules in the main directory. I think the problem is related to it not correctly detecting that a file or directory exists.

    This logic is working to redirect it to the subdirectory:
    <rule name="domain" stopProcessing="false">
                        <match url=".*" />
                            <add input="{HTTP_HOST}" pattern="^(www.)?domain\.com$" />
                            <add input="{PATH_INFO}" pattern="^/directory($|/)" negate="true" />
                        <action type="Rewrite" url="\directory\{R:0}" />
    When I use this logic the redirect never fires when I ask for a file. I have traced that {REQUEST_FILENAME} is returning the right path to a file but it doesn't realize that it's a file.
    <match url="(.*)"/>
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="^(www\.)?domain\.com$" />
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" />             
                        <action type="Redirect" url="tatravel\readme.html" />     
    I have this code for the permalinks which works until I try to go to /wp-admin. Note the cludgy way I had to get files recognized though. Shouldn't be necessary:
    <rule name="Rewrite domain.com permalink" stopProcessing="true"> 
                        <match url="(.*)"/> 
                        <conditions logicalGrouping="MatchAll">    
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> 
                            <add input="{DOCUMENT_ROOT}/{R:1}" matchType="IsDirectory" negate="true" />
                            <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}" pattern="\.txt|\.js|\.jpg|\.jpeg|\.gif|\.png|\.bmp|\.php|\.aspx|\.aspx|\.html|\.pdf|\.mps|\.wav\.ico\.tiff" negate="true" /> 
                            <add input="{REQUEST_FILENAME}" pattern="\.css|\.php|\.json|\.zip" negate="true" /> 
                            <add input="{REQUEST_FILENAME}" pattern="\.aif|\.cda|\.wpa|\.ogg|\.wpl" negate="true" /> 
                            <add input="{REQUEST_FILENAME}" pattern="\.zip|\.arj|\.deb|\.pkg|\.rar|\.rpm|\.tar\.gz" negate="true" /> 
                            <add input="{REQUEST_FILENAME}" pattern="\.bin|\.dmg|\.iso|\.toast|\.vcd" negate="true" /> 
                            <add input="{REQUEST_FILENAME}" pattern="\.csv|\.doc|\.rtf|\.dat|\.db|\.log|\.mdb|\.sav|\.sql|\.ttar|\.xml|\.xls|\.xlsx" negate="true" /> 
                            <add input="{REQUEST_FILENAME}" pattern="\.fnt|\.fon|\.otf|\.ttf|\.woff2" negate="true" />
                            <add input="{REQUEST_FILENAME}" pattern="\.dll|\.ini|\.msi|\.tmp|\.cfg|\.cer|\.cfm|\.cgi|\.pl|\.css|\.htm|\.html|\.js|\.jsp|\.part|\.php|\.py|\.rss|\.xhtml|\.xsd" negate="true" />                        
                            <add input="{REQUEST_FILENAME}" pattern="\.3g2|\.3gp|\.avi|\.flv|\.h264|\.m4v|\.mkv|\.mov|\.mp4|\.mpg|\.mpeg|\.rm|\.swf|\.vob|\.wmv" negate="true" />                        
                            <add input="{REQUEST_FILENAME}" pattern="\.key|\.odp|\.ppt|\.pps|\.pptx" negate="true" />                        
                        <action type="Redirect" url="\tatravel\index.php" /> 
  4. Elshadriel

    Elshadriel Winhost Staff

    Your rules for the web.config file in the wordpress directory seem too complicated. This is all that is necessary:

    <?xml version="1.0" encoding="UTF-8"?>
        <trust level="Full" />
        <!-- Set the default document -->
            <remove value="index.php" />
            <add value="index.php" />
        <directoryBrowse enabled="false" />
            <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" />
              <action type="Rewrite" url="index.php" />
  5. I agree. The problem is that it wasn't working. I have another site that is working perfectly but I can't get this one to work. I just copied the text above and the main site loads fine, so do the wp-admin. However, if I try to go to a page or post I get a 404 error. It seems to be ignoring the redirect to the index.php. Like I said, I have another site that's working fine but I've tried copying the same web.config for this site (changing the urls and paths and such) and this is the result. I even tried reinstalling it again and rebuilding the directory. Ugh.
  6. Okay, on further testing, it isn't applying rules in the subdirectories. As soon as I change the permalink to "%postname%" it fails with a 404 error. It's not redirecting to index.php, it's trying to navigate to the requested file (which isn't there.) I've tried having the web.config in the subdirectory and using location tags. It simply seems to ignore it. I've tried to a hard redirect/rewrite (both) with no conditions and it doesn't redirect.
  7. Elshadriel

    Elshadriel Winhost Staff

    I'm afraid I don't have anything more I can offer you to help. I tried setting this up myself but was unable to. The problem is you're using IIS to apply URL Rewrites (for the domain redirection) and then you're trying to apply WordPress' rules for Permalinks. I was only able to find this documentation on Microsoft, but it only applies to a single site.

Share This Page