IIS Web.Config 301 Rewrite for PHPBB3

IISWebConfig301RewriteforPHPBB3

If you delete a forum from PHPBB3 and don’t want to hurt your SEO it’s recommended that you put 301 redirects in place so you’re not returning 404s back to the search engines.

When you haven’t got .htaccess files to work with and instead are faced with the daunting task of using web.config files to run on IIS it can be tricky, especially when you’re dealing with a technology that uses query strings and parameters like PHPBB3.

We can address this issue by employing Rewrite Maps that means you can essentially create a simple list of source and target redirects that are sensitive to the query strings and parameters.

By using a 301 redirect you achieve two things.  The first is that it will tell ALL search engines to remove the entry from their database and replace it with the destination and it means that anyone who clicks the link will get redirected to the new content.  .htaccess editing is more of a known quantity and it’s only when you start trying to user the Microsoft IIS web.config approach that issues arise.  Doing simple redirects is easy, but not when the URL’s have query strings or parameters.  This is the reason most people complain that normal redirects or rewrites don’t work with PHPBB3.

Let’s for example, say that in your PHPBB3 forum you delete the following forums:

http://www.website.com/viewforum.php?f=20
http://www.website.com/viewforum.php?f=21

But then realise that these have already been indexed by Google, or even worse – someone has created a high value link to one of them.

You decide that you want to redirect them to two other relevant forums:

http://www.website.com/viewforum.php?f=40
http://www.website.com/viewforum.php?f=41

You would use the following code in your web.config file: (double click to select all code for copy/paste)

<?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <system.webServer>
    <rewrite>
    <rules>
      <rule name="Redirect Rule 1 for Old Forum">
      <match url=".*" />
      <conditions>
        <add input="{Old Forum:{REQUEST_URI}}" pattern="(.+)" />
      </conditions>
      <action type="Redirect" url="{C:1}" appendQueryString="false" />
      </rule>
    </rules>
    <rewriteMaps>
    <rewriteMap name="Old Forum">
      <add key="/viewforum.php?f=20" value="/viewforum.php?f=40" />
      <add key="/viewforum.php?f=21" value="/viewforum.php?f=41" />
    </rewriteMap>
    </rewriteMaps>
    </rewrite>
    </system.webServer>
  </configuration>

The key to this whole process is the rewriteMap element of the web.config.  It allows you to very efficiently list redirects together which means less code and less effort to maintain the file.

You can then test to make sure your 301 redirects are being processed properly by using a site such as those found from this Google search

I hope you’ve enjoyed this post, please feel free to share your thoughts below.

Author: BigGeek

Wayne is a self-proclaimed geek, IT Professional, father of two and husband who's still much closer to 40 than 50. When he's not busy in an otherwise hectic life he takes time to blog on all things that warrant an online opinion. Founded in 2012, ePINIONATED has been a guilty pleasure for Wayne, giving him an online voice in a very noisy Interweb – some of which might even be useful, maybe.

3 thoughts on “IIS Web.Config 301 Rewrite for PHPBB3”

We would love to hear from you...