HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Enabling Clean URLs on IIS Installations

ShadowdareShadowdare r_j MVP
edited August 2014 in Tutorials

If you use IIS on Windows to host your Vanilla forum and would like to enable clean URLs, then follow these steps below.

Be sure to install the IIS Rewrite module first.

Try finding this line in Vanilla's /conf/config.php file. If it doesn't exist, add the line.

$Configuration['Garden']['RewriteUrls']

Set the setting to true. The line should look like $Configuration['Garden']['RewriteUrls'] = true;.

Next, in your website's Web.config file, add a rewrite section so that the file looks like this. You might have other sections in the file, but the important part is to have the rewrite block within the system.webServer section:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
          <rules>
            <rule name="Vanilla Rule 1" stopProcessing="true">
              <match url="^(.*)$" ignoreCase="false" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
              </conditions>
              <action type="Rewrite" url="index.php\?p={R:1}" appendQueryString="true" />
            </rule>
          </rules>
        </rewrite>
    </system.webServer>
</configuration>

Known bug with IIS and RewriteURLs: discussion names with many unicode characters in the URL cause a not found error.

For Vanilla forums installed in sub-folders, you may have to tweak the rewrite rule to make it work. If anyone has any experience with doing so, please leave a comment below and let us know how you made it work.

Add Pages to Vanilla with the Basic Pages app

Comments

  • Matt2kMatt2k New
    edited May 2017

    To use this in a subfolder, you only need to add a "<clear />" tag. This removes any existing rewrite rules that might be inherited from parent folders.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <clear />
            <rule name="Vanilla Rule 1" stopProcessing="true">
              <match url="^(.*)$" ignoreCase="false" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
              </conditions>
              <action type="Rewrite" url="index.php\?p={R:1}" appendQueryString="true" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    
  • Thank you so much! Exactly what i was looking for.

  • Not found issue.

    I have pi.php file in wwwroot folder. I want to run it as domain.com/pi

    I have set $Configuration['Garden']['RewriteUrls'] to true and following code in web.config:

    <rule name="PI Test">

              <match url="pi" />

              <action type="Rewrite" url="pi.php" />

            </rule>

    But, it still doesn't work. Any help is much appreciated.

Sign In or Register to comment.