WordPress running on IIS and ugly permalinks starting with index.php

Wednesday, November 3, 2010 12:27
Posted in category Web, Wordpress

You may have experienced when running WordPress on IIS that the permalinks have that ugly index.php included.

Pretty way: www.mysite.com/2010/11/mypost
IIS way: www.mysite.com/index.php/2010/11/mypost

By tweaking the .htaccess and using some rewrite rules this can be fixed. (ISAPI_Rewrite required)

What has to be dont is to rewrite all “pretty way” links to “iis way” links by including index.php into the url.

I found the solution at http://www.richardshepherd.com/wordpress-iis-permalinks-and-index-php/ so I’m gonna include his .htaccess code here in case his site becomes unavailable.


# -------------------------------------------------------------------------
# Kickstart the Rewrite Engine and set initial options
# -------------------------------------------------------------------------

RewriteEngine On
RewriteCompatibility2 On
RepeatLimit 200
RewriteBase

# ————————————————————————-
# WORDPRESS, WINDOWS & ISAPI DOCUMENTATION
# ————————————————————————-
# These are the WordPress redirects we need in place for a Windows Server
# running PHP & MySQL
# We had some issues configuring ISAPI with WordPress and so here are the
# solutions in case we need them again!!

# ————————————————————————-
# PERMISSIONS SETTINGS
# ————————————————————————-
# The following folders:
# wp-admin
# wp-content
# MUST HAVE read/write/modify permissions set for internal user accounts

# ————————————————————————-
# ESSENTIAL WORDPRESS REWRITES
# ————————————————————————-

# Redirects ‘www.yourblogsite.com/index.php’ to ‘www.yourblogsite.com/’

RewriteRule ^/index\.php$ / [NC,P,R=301]

# Rewrite ‘www.yourblogsite.com/anything/’ to ‘www.yourblogsite.com/index.php/anything/’
# NB. The user does not see this rewrite.
# Must also go into WordPress > Settings > Permalinks and select ‘custom’
# and then REMOVE ‘index.php’ from the custom URL it generates

# The first line is a condition so it doesn’t apply the rule to the wp-admin part of the site

RewriteCond %{REQUEST_URI} !/wp-admin
RewriteRule ^/(.*)/$ /index\.php/$1 [NC]

# Finally, redirect ‘www.yourblogsite.com/anything/anything/index.php’
# to ‘www.yourblogsite.com/anything/anything/’

RewriteRule ^/(.*)/index\.php$ /$1/ [NC,P,R=301]

# ————————————————————————-
# END OF ESSENTIAL REWRITES
# ———————————————————-

You can leave a response, or trackback from your own site.

Leave a Reply

Connect with Facebook