• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

WordPress + Xenforo rewrite rules on IIS 7.5

Blandt

Well-known member
Ok y'all Beta 4 has fixed numerous issues and today I was successful configuring IIS to rewrite properly for both Wordpress and Xenforo nested in the same folder like this :

c:\www\domain\wordpress\community so the URL is like so : www.domain.com ----> Wordpress
and www.domain.com/community ------> Xenforo

So the idea is to set an application inside Wordpress to point to xenforo and we need 2 web.config files. the first located at the root of Wordpress and the second at the root of xenforo.

Here we go:
This is the Wordpress web.config : and please note that I have added a canonical rule to redirect domain.com to www.domain.com If you don't want it please remove that one rule. And also have setup support@domain.com to use your local SMTP server (again edit as appropriate)


Code:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>

    <defaultDocument>
      <files>
        <clear />
        <add value="index.php" />
      </files>
    </defaultDocument>
    <rewrite>
      <rules>
        <rule name="CanonicalHostNameRule1">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:1}" />
        </rule>
        <rule name="WordPress Rule" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php/{R:1}" />
        </rule>
      </rules>
      <outboundRules>
        <preConditions>
          <preCondition name="ResponseIsHtml1">
            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
          </preCondition>
        </preConditions>
      </outboundRules>
    </rewrite>
  </system.webServer>
  <system.net>
    <mailSettings>
      <smtp from="support@domain.com">
        <network host="localhost" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

This is Xenforo web.config .. and it goes in the community folder within Wordpress where xenforo files are located :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <clear />
        <rule name="CanonicalHostNameRule1">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:1}" />
        </rule>
        <rule name="XenForo Rule 1" stopProcessing="true">
          <match url="^.*$" />
          <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
          </conditions>
          <action type="None" />
        </rule>
        <rule name="XenForo Rule 2" stopProcessing="true">
          <match url="^(data|js|styles|install)" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
          <action type="None" />
        </rule>
        <rule name="Xenforo Rule 3" stopProcessing="true">
          <match url="^.*$" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
          <action type="Rewrite" url="index.php" />
        </rule>
        <rule name="Xenforo Rule 4" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
<system.web>
        <customErrors>
            <error redirect="http://www.domain.com/community/" statusCode="403" />
        </customErrors>
    </system.web>

</configuration>

Ok that's it :) ... Let me know if you need any special setup ... oh and make sure you have the URL rewrite module installed
 
I do not run Windows as web server, but thank you for this. Forwarded the thread to a friend who still runs Windows. he can certainly use this. :)
 
Oooh and the same rules work for xenforo within concrete5 as well :)

If you need a TotalCache or SuperCache configuration for Wordpress let me know .. I will post the necessary bits :)
 
Update :

Xenforo requires users to be logged in to view full size attachment. When guests click an attachment IIS throws a 403 Forbidden error (ugly :D)
So we need to explicitly tell IIS how to handle such errors.
So in the xenforo web.config right before the closing tag </configuration> ad this :
<system.web>
<customErrors>
<error redirect="http://www.domain.com/community/" statusCode="403" />
</customErrors>
</system.web>


I have updated the post above to reflect the change If you come across an exception I have missed please post here :)
 
Top Bottom