URL Rewrite on IIS7 for Wordpress URL Rewrite on IIS7 for Wordpress wordpress wordpress

URL Rewrite on IIS7 for Wordpress


I'm using the ManagedFusion Url Rewriter and a custom 404 error page on my blog.

The ManagedFusion Url Rewriter requires a file called ManagedFusion.Rewriter.rules that mimics .htaccess, I had to play around with it quite a bit to get it right so I'll include what I currently have in mine:

#  Managed Fusion Url Rewriter#  http://managedfusion.com/products/url-rewriter/##  Developed by: Nick Berardi#       Support: support@managedfusion.com#RewriteEngine on## Place Rules Below## misc WordPress rewritesRewriteRule ^/wp-login\.php$ /wp-login.php [L]RewriteRule ^/wp-comments-post\.php$ /wp-comments-post.php [L]RewriteRule ^/wp-admin/(.*)$ /wp-admin/$1 [L]# deny access to evil robots site rippers offline browsers and other nasty scumRewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]RewriteCond %{HTTP_USER_AGENT} ^attach [OR]RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]RewriteCond %{HTTP_USER_AGENT} ^ZeusRewriteRule ^.* - [F,L]# remove wwwRewriteCond %{HTTP_HOST} ^www\.robboek\.com$ [NC]RewriteRule ^(.*)$ http://robboek.com$1 [R=301]# redirect old urlsRewriteRule ^/2008/12/blog-on-hold.html$ /2008/12/12/blog-on-hold/ [R=301]RewriteRule ^/2008/11/google-chrome-wont-start-in-vista-x64\.html$ /2008/11/16/google-chrome-wont-start-in-vista-x64/ [R=301]RewriteRule ^/2008/11/pass-community-summit-2008-events.html$ /2008/11/14/pass-community-summit-2008-events-calendar/ [R=301]RewriteRule ^/2008/11/fort-stevens-camping-trip.html$ /2008/11/14/fort-stevens-camping-trip/ [R=301]RewriteRule ^/2008/10/first-post.html$ /2008/10/10/first-post/ [R=301]RewriteRule ^/blog/CommentView,guid,1d8cba50-0814-4c89-86df-eca669973e8e.aspx$ /2006/09/29/junctions-in-windows-vista/ [R=301]RewriteRule ^/blog/2006/09/29/JunctionsInWindowsVista.aspx$ /2006/09/29/junctions-in-windows-vista/ [R=301]# rewrite all nonexistent files and directories to use index.php for WordPressRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ /index.php$1

The rules handle the pretty urls, remove the www, and redirect several old urls from a previous blog.

I also have a file "404.php" that I have setup as my custom 404 error page. This is not needed for the pretty urls, but will allow you to use the wordpress 404 page in custom themes. Here are the contents:

<?php$qs = $_SERVER['QUERY_STRING'];$pos = strrpos($qs, '://');$pos = strpos($qs, '/', $pos + 4);$_SERVER['REQUEST_URI'] = substr($qs, $pos);$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];include('index.php');?>

I hope that helps. It has been working very well for me so far.

-Rob

Update: I just posted a blog article on my experience using WordPress on IIS7


Thank you all for the suggestions.

My host ended up installing IIRF and it worked like a charm. There is a file called IsapiRewrite4.ini for the rewrite rules. In order to get my Wordpress install running without the index.php in the URL, all I had to do was add:

RewriteRule ^/sitemap.xml$   - [L]RewriteRule ^/(?!index.php)(?!wp-)(.*)$ /index.php/$1

The first line allows requests for a sitemap.xml file. The second line handles removing index.php from the URL. It seems to be fine from a performance standpoint as well, I haven't seen any issues with pages responding slowly at all.

Hopefully this will help somebody else who needs similar functionality.


Changing the 404 page to index.php is supposed to do the trick. If it does not, the plugin may not support IIS.

There is a xml "web.config" file in IIS that does what .htaccess does in Apache HTTPD. (i.e. Override web server setting by static configuration file). It is widely used in ASP.NET application.

Please read Enable custom errors in WordPress on IIS 7.0 If this does not work either, you may try to ask your service provider to set it for you.They can configure this setting via IIS Management Console GUI.