views:

2266

answers:

3

I am using shared hosting with IIS7 and support for PHP. I am trying to run a wordpress blog with "pretty urls" (removing index.php). The hosting provider doesn't want to install the URLRewrite module, so that option isn't available to me. I found a plugin for wordpress that will remove the index.php from permalink URLs and changing the 404 page to index.php is supposed to do the trick... that isn't working either.

I'm familiar with URL rewriting for an ASP.NET website, but I'm not sure how I would go about it for PHP. The hosting setup seems to support ASP.NET and PHP at the same time, so I'm thinking it would be possible to run the rewrite code through ASP.NET, but I'm not sure how to go about it.

Does anybody have any experience with this or any ideas about the best approach to take. If anything leads me in the right direction or if I figure it out myself, I will be more than happy to share the code here for anybody else that may need it.

+5  A: 

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: [email protected]
#
RewriteEngine on

#
# Place Rules Below
#

# misc WordPress rewrites
RewriteRule ^/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 scum
RewriteCond %{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} ^Zeus
RewriteRule ^.* - [F,L]

# remove www
RewriteCond %{HTTP_HOST} ^www\.robboek\.com$ [NC]
RewriteRule ^(.*)$ http://robboek.com$1 [R=301]


# redirect old urls
RewriteRule ^/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 WordPress
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /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

Rob Boek
I'm currently waiting to find out why my custom 404 settings aren't working but once it has been fixed, I'll give this a shot. Thanks!
Andrew Van Slaars
A: 

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.

Dennis Cheung
+3  A: 

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.

Andrew Van Slaars