Subdirectory web.config Rewrite

Discussion in 'Site Programming, Development and Design' started by Jay Shaw, Oct 18, 2021.

  1. Hello,

    My base domain is www.MyDomain.com. I've installed WordPress application in /wp2021/ subfolder.

    I created a web.config file in the root directory which successfully redirects all incoming traffic to this subfolder. Here's the web.config file in my root folder (works great):

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>

    <system.web>
    <trust level="Full" />
    </system.web>

    <system.webServer>

    <directoryBrowse enabled="false" />

    <rewrite>
    <rules>
    <!-- Redirect Any Traffic to Base URL to Subfolder /wp2021 -->
    <rule name="MyDomain.com" stopProcessing="true">
    <match url=".*" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^(www.)?MyDomain.com" />
    <add input="{PATH_INFO}" pattern="^/wp2021/" negate="true" />
    </conditions>
    <action type="Rewrite" url="\wp2021\{R:0}" />
    </rule>
    </rules>
    </rewrite>

    </system.webServer>

    </configuration>

    Like I said, this works great when I go to www.MyDomain.com, however once there if I click on any links, then it starts using my secondary url in the address bar. It looks bad is probably isn't a good idea. For example, clicking on the ABOUT link send me to this URL:


    Why is it using my secondary domain???

    I did set this WordPress site up before the DNS was fully propogated - do I need to reinstall it? Or is there a way to fix it using a web.config file rule? If so, then can I put it in that original root folder web.config or does it need to go in the subfolder's web.config?

    My subfolder's web.config file is currently this:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>

    <system.web>
    <trust level="Full"/>
    </system.web>

    <system.webServer>

    <!-- Set the default document -->
    <defaultDocument>
    <files>
    <remove value="index.php"/>
    <add value="index.php"/>
    </files>
    </defaultDocument>

    <!-- No Directory Browsing -->
    <directoryBrowse enabled="false"/>

    <!-- Rewrite Rules -->
    <rewrite>
    <rules>
    <rule name="WordPress: http://mydomain.w33.wh-2.com/wp2021" 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>

    Can someone please help me understand what I need to do to stop exposing my secondary url to the world?

    Thanks, Jason
     
  2. OK - I fixed it.

    Nothing to do with the web.config. Instead, I decided to delete all WordPress files plus the MySQL Database and start over.

    Now it works.
     
    Elshadriel likes this.

Share This Page