The eternal battle is over, mostly: getting your WordPress permalinks to work on your Windows IIS web server with ISAPI Rewrite installed.
Some Requirments.
.htaccess file. Here’s an example that has worked with WordPress 2.7.x, ISAPI Rewrite 3, and Windows Server 2003/IIS 6.0:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]
How it works.
Even with ISAPI Rewrite, your WordPress permalinks most likely will be broken without the ugly, prepended /index.php/. The problem is that the REQUEST_URI server variable is not sent by IIS or ISAPI Rewrite. This plugin solves this.
This solution is more elegant that changing the WordPress core files because it allows you to easily upgrade WordPress without additional maintenance.
Download and Documentation.
You can download ISAPI Rewriter from the WordPress Plugin directory.
You can view documentation at the ISAPI Rewrite plugin page.
RSS feed for comments on this post. TrackBack URL
Seagoat says…
I followed all the steps outlined above (for a client’s site), and the rewrite works, but somehow the stylesheet gets nuked in the process. If I undo all the changes, my styles come back, but then of course I don’t have the index.php-less URLs. :-/ Any thoughts?
andy says…
@Seagoat what version of ISAPI Rewrite are you using? Needs to be 3.0
Try changing it to this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]
I may have made a typo in the .htaccess configs and left the underscore out of the server variable within the rewrite conditions. I’ll update the post!
Seagoat says…
Thanks for getting back to me so quickly! I am indeed using 3.0, and adding the underscores seems to have fixed the problem. Yay!
I could swear that I tried removing the comments and conditionals from the default WP .htaccess and still had problems, but that might just be me being crazy. :p
Thanks again!
Joseph says…
Hi there,
Just wondering if you could shed some light. When I installed WordPress on my Windows server, a .htaccess file was not created (unless I can’t see it), and I was wondering if you could share with me where it should go? And is the following code all I need to place it in?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]
Also, once created, does the server or IIS require a reboot?
Great plug-in!
Thanks, Joseph.
andy says…
@joseph this plugin requires IIS 6 and ISAPI Rewrite 3.0, as this version supports .htaccess files and the rewrite directives included here.
There should now be a sample .htaccess file in the plugin download from the WordPress plugin repository.
If you need help with an ISAPI Rewrite installation, be sure to hit up the good folks at Helicon.
Let me know how this helped!
andy says…
@joseph and thanks for the kind words!
JD says…
It would be nice if you could expand this post and mention what setting to select when logged in as admin on wordpress i.e the permalinks section
andy says…
@JD The beauty is this allows you to use any of WordPress’ default permalink settings or your own custom setting.
IIS, ISAPI Rewrite, the .htaccess file, and this plugin will make all URL’s that aren’t existing files or directories redirect to WordPress’ main controller script.
Joseph says…
Hi Andy,
Sorry, I still don’t understand where to put the .htaccess file?
Does it go somewhere in the WordPress installation folder? Or does it go in the root of the website? Or somewhere else?
Much appreciated.
Ross.
andy says…
@Joseph The
.htaccessfile needs to be in the installation directory of WordPress.If you have WordPress installed in
C:\Inetpub\wwwroot\theandystratton.com\then the location of the.htaccessfile would beC:\Inetpub\wwwroot\theandystratton.com\.htaccessAgain, make sure you hit up the ISAPI Rewrite Support Forums for more detailed support with their product.
Joseph says…
Hello Andy,
Here are the steps I took to install your plug-in, unfortunately I still can’t get it going.
1. Installed ISAPI Rewrite 3 Lite version (for now). I did not make any changes, simply accepted the defaults from the .msi
2. Created a .htaccess file as you described, and placed it in the same directory as the Wordpress index.php file (which is one directory above the other Wordpress folders/files)
3. Installed / Activated your plug-in
4. Changed my permalinks to custom structure as follows; /%postname%/
When I hover over a post title it shows the correct URL, but when I click the post, I get “The system cannot find the file specified.”
Any thoughts?
Thanks, Joseph.
andy says…
Joseph, sounds like an issue with ISAPI Rewrite 3. I’d make sure you’ve got it installed and handling .htaccess properly. I would contact their support to ensure that’s functioning properly. It sounds like WordPress is doing it’s job.
You can add the following PHP snippet to a page template:
<?php var_dump($_SERVER); ?>
and make sure that the URL is present in $_SERVER['REQUEST_URI'], if it is, then the plugin is working as well.
Joseph says…
Andy,
I don’t think this will not work with the lite version of ISAPI Rewrite 3. I installed the demo of the full version, and everything is good.
I actually found a comment about this on Wordpress.org.
You should edit the top of your post
Joseph.
andy says…
Joseph,
I have a working Windows Server 2008 installation using IIS 6.0, WordPress 2.7, and ISAPI Rewrite 3 (Lite). See this screen shot:
Using ISAPI Rewrite 3, Lite
Joseph says…
Hi Andy,
Strange thing… when I had the lite version installed, the only way to see the right panel (that shows the .htaccess contents) was to highlight the top node, i.e. IIS Web Sites.
When I highlighted one of the individual websites, the entire ISAPI Rewrite 3 screen went gray with a single message (something about doesn’t support… or not defined… I don’t remember).
Then when I installed the full version, and highlighted any website in the tree, the right panel was available, and it displayed the contents of .htaccess (if it found one).
Is it possible the lite version only supports 1 site?
Great plug-in btw, nice and clean, and does the job!
Thanks, Joseph.
andy says…
Nailed it! The Lite version does only support 1 site. That explains the disconnect. If you’re going to implement this setup, I’d recommend getting the full version, definitely worth it.
Thanks for the compliments, hope it helps you out!
Kerry says…
Hi
Wonder if you could offer me some advice. I added Helicon Isapi 3 to my /blog/ subdirectory, edited the httpd.conf file (assume this is the equivalent to htaccess) file to to add the rules you stated above.
I then activated your plugin and tried changing permalinks and my entire blog 404s. Not sure whya s your solution sounds a great alternative to fiddling with code!
To be honest, also tried to do this the manual way by adding rules
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?p=$1 [NC,L]
and then adding
if (isset($_SERVER['HTTP_X_REWRITE_URL']))
{
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
to the index.php file in the /blog/ subdirectory and then within httpdocs/blog/wp-content/themes/freshnews (freshnews being my theme) . When I add it at this level /blog/ the index page works and all posts 404. Also the code entered into the index.php seems to be pulled into my header, distorting my stylesheets.
When I add it at theme level nothing happens. Although I’m yet to try to add to index.php in /wp-content/ and/or /themes/
Seriously, do you have any idea what my problem could be with your tool? I’m going crazy!
I’m also posting my question re the manual code change issue on the Helicon forum, but thought you may have some ideas there.
Anyway, any advice appreciated!
Ash says…
Ok so i have installed this plugin successfully on the root of a site and on a subdomain of another site using the following .htaccess in the root of the site/subdomain:
# BEGIN WordPress
Options +Followsymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
CheckSpelling On
# END WordPress
and the following permalink:
/%year%/%monthnum%/%postname%
But now i’ve moved the blog to http://www.mydomain.com/blog and it doesn’t work at all.
I’ve tried creating a new site on the same hosting (all of the above mentioned sites are hosted on the same reseller hosting cp – windows) and again setting the blog up in the /blog subfolder, with htaccess in that subfolder (i’ve even copied and pasted the exact same one from your example above) and it doesn’t work – file not found.
Why would it work prefectly on the root of 4 or 5 sites but not in a subfolder?
Great plugin, any help is greatly appreciated
andy says…
I don’t have any tests within a subdirectory, but I would try updating the RewriteBase directive to be:
RewriteBase /path-name/
Right now it’s assuming the root is the base directory. Give that a try and let me know, but currently this has only been successful for me in a root directory scenario.
Ash says…
Wow thanks for the amazingly fast reply!
I figured it was the .htaccess but i dont know too much about them. I tried what you suggested and it didnt work, But then i figured i’d try the line at the bottom and it did work:
RewriteRule . /blog/index.php [L]
So for anyone who installs their blog in a subdirectory that should patch it up.
Cheers once again Andy, you’re a star :0)
andy says…
@Ash Thanks, I’m glad you got it working. Ha, if I were a true star I would’ve caught the RewriteRule as well ;p
Junaid says…
Nice work on this, I am surprised this plugin is not more popular considering how many Wordpress installations would be hosted on Windows.
Please keep it maintained and up to date. It seems to work well on Windows 2008/IIS7 and Wordpress 2.9 – so you could probably update the compatibility version list.
Thanks and good job.
andy says…
@Junaid thanks! I’m not sure if it’s needed on IIS 7 as I think it has rewriting capabilities, it was mainly built for IIS 6 and ISAPI Rewrite when I had to work in that environment and the support was limited to editing core WP files.
Good call on updating the stats, thanks for letting me know it’s working on Windows 2008 + IIS 7 as well as WP 2.9. I figured newer versions were supporting (and my workload has been full) so I haven’t had a chance to setup a new virtual environment to test the new versions.
Thanks again for the kind words and I’m glad it helped you out!