I recently launched a new WordPress site running on IIS (yes, you read correctly). The web host had ISAP Rewrite installed so we planned to use that to support Apache mod_rewrite rules.
I had used the ISAPI Rewrite filter before to handle URL rewriting like the rewrite rules that come with WordPress to support permalinks. But I had never done a 301 Redirect on IIS with this method. How hard could it be? I was replacing an ASP.NET site and needed to redirect old links like this:
OLD: http://www.example.com/AboutUs.aspx NEW: http://www.example.com/about-us/
In Apache you would simply do a 301 redirect by adding the following line to .htaccess:
# This will not work using ISAPI Rewrite Redirect 301 /AboutUs.aspx http://www.example.com/about-us/
I assumed the same syntax would work in .htaccess using ISAPI Rewrite. WRONG!
It turns out that the Redirect directive is part of Apache mod_alias and not part of mod_rewrite. So, how do you do a 301 redirect using mod_rewrite? You can do all sorts of crazy URL rewriting using mod_rewrite but I just wanted to do a simple page to page redirect!
Well, here’s how I eventually got the redirect for the About Us page and the default.aspx page to work:
RewriteRule ^default\.aspx / [R=301,L] RewriteRule ^AboutUs\.aspx /about-us/ [R=301,L]
I hope this helps if you are trying to do a 301 redirect using ISAPI Rewrite.