Permalink for WordPress – IIS 6 mod_rewrite FIXED – Free

This entry was posted by KyleCaulfield on Wednesday, 17 February, 2010 at

If you install WordPress on IIS you will notice your friendly URLs do not work.  This is because WordPress wants to use an apache add-on called “mod_rewrite.”  The quick rundown of that this does is it will take your friendly browser URL and actually change them to index.php on the back end.  One problem with this method is that IIS does not load apache mods.  Here is an easy and free way around this:

  1. On your IIS Server download and install ISAPI_Rewrite Lite.  This filter does the job of mod_rewrite for IIS.  When downloading make sure to use the free Lite version.  This Lite version does not limit the product very much and will be perfectly fine (and free) for our wordpress blog.  Just install Rewrite Lite to the default locations for this tutorial.
  2. Next add the ISAPI filter to your IIS Site.
    You will find this setting by right clicking yourIIS site -> properties -> ISAPI filters tab -> Add …  Name the filter whatever you wish and your path to your executable should be:
    C:\Program Files\Helicon\ISAPI_Rewrite3\ISAPI_Rewrite.dll
    Click OK on both windows to save your settings.
  3. Next navigate to C:\Program Files\Helicon\ISAPI_Rewrite3
    Here we will edit httpd.conf  (Note:  This is the difference between the pay version and the Lite version.  In the pay version you will need to edit the .htaccess file on your web folders root)
  4. Open the httpd.conf file in wordpad and paste in these lines:
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?p=$1 [NC,L]
  5. Save and exit this file.
  6. To complete your IIS changes, Go to start, run and run the command:  iisreset /restart
  7. Now lets change your WordPress settings.  Navigate to yourblog/wp-admin
  8. Navigate to the left side menu bar -> settings -> Permalinks
  9. Now you get to choose how you want your posts to look.  I choose a custom setting and just: /%postname%  This is how you see this blog working today.
  10. Click “Save Changes” and you should see your new friendly URLs!
Tags: Friendly URL, IIS, mod_rewrite, permalinks, Wordpress
Category: Fix-it, Wordpress
You can follow any responses to this entry via RSS.
You can leave a comment or trackback from your own site.

128 Responses to “Permalink for WordPress – IIS 6 mod_rewrite FIXED – Free”

  1. spacer Drew
    February 22, 2010 at 7:20 pm

    Tried this step by step and no luck getting it to work. The current version ISAPI rewrite (v3) installs properly and does the majority of the updates above automatically with the exception of step 4. Manually edited the httpd.conf file and WordPress STILL will not allow permalinks.
    Any updates regarding this?

    Reply
    • spacer KyleCaulfield
      March 12, 2010 at 6:25 pm

      Where is your HTTPD.CONF located? it needs to be in: C:\Program Files\Helicon\ISAPI_Rewrite3

      Reply
  2. spacer Lars CMS Meyer
    March 9, 2010 at 12:11 pm

    Very nice wordpress trick – this works like a charm. No need to install og buy components to help rewriting, this is all you need. 5 minutes after finding this guide, my wordpress blog is now working with url rewritten permalinks, perfect spacer

    Excellent and easy follow guide, i’d recommend it to others.

    Reply
  3. spacer Jared
    March 12, 2010 at 12:14 am

    Hi Kyle- I really wanted this to work, but it doesn’t for me. At first, it just redirects to the generic Index.php that shows all of the info for the PHP version that’s currently installed. So then I renamed that generic index.php file to see if it would redirect to the correct one (the one associated with the blog posts). But it didn’t work…it just 404s on me.
    I know you probably can’t answer individual comments, but if you have any insight, I’d love to hear it.
    Thanks!

    Reply
    • spacer KyleCaulfield
      March 12, 2010 at 6:24 pm

      It sounds like your httpd.conf is not correct… can you post it? Also, the httpd.conf needs to be in the folder: C:\Program Files\Helicon\ISAPI_Rewrite3 (or wherever you have it installed)

      Reply
  4. spacer Jared
    March 12, 2010 at 7:15 pm

    Hi Kyle-

    Thanks for writing back.
    Yes, the httpd.conf is located in the C:\Program Files\Helicon\ISAPI_Rewrite3 folder.
    The only thing listed in that file is the lines of code that you posted in the article:
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?p=$1 [NC,L]

    Before I pasted them, it was an empty file.
    As I said, it worked in the sense that it redirected to the “index.php” file that is located in my website’s root folder (which is just the standard index.php file that you get when you’re testing to confirm that PHP is installed correctly). But once I renamed that file (for testing purposes), the redirect would simply go to a 404 page.

    So it would appear that the redirect is working somewhat, but it seems to be pointing to the wrong file location. Does that sound about right to you?

    In the past, I’ve had a lot of issues with giving the internet user account certain rights to other folders. Do you think that might be an issue here? I wouldn’t think so, since the “work” is being done on the server side, but stranger things have happened.
    Thanks again for any insight you can give. I appreciate it.

    Reply
  5. spacer Jared
    March 14, 2010 at 1:14 am

    Okay, a bit of an update. Hopefully this can help us figure out what’s going on.

    I changed the fourth line of code in the the httpd.conf file to include the path to the correct index.php file. So the new line looks like:
    RewriteRule ^(.*)$ blog/index.php?p=$1 [NC,L]

    Since my blog is not in the root directory, this tells the rewrite where to find the correct index.php. I can’t believe I didn’t think of that earlier. However, it still doesn’t function correctly.
    Now, no matter which post I click on, it simply loads the “home” page of the blog. The browser address bar shows a nice permalink (www.mywebsite.com/blog/postname), but what appears on the screen is just the home page, not the actual post.

    So we’ve taken two steps forward and one step back.

    BTW, if I include the “index.php” as my permalink setting in WordPress, everything works great. (e.g. www.mywebsite.com/blog/index.php/postname)

    But I’d prefer not to include that reference to index.php if I can help it.

    Any thoughts?

    Reply
    • spacer KyleCaulfield
      March 14, 2010 at 3:01 pm

      Jared — I have not tried to have my blog posted anywhere but the root site, but have you tried changing the line:
      RewriteBase /

      To:
      RewriteBase /blog/

      I think this might help. As for the security I had unrelated problems to that before but if security was not set correctly I think IIS would request a username and password from you. This issue is something with out ISAPI rewrite. Don’t give up! It is trying to work, we just need to massage the settings a little bit.

      Kyle Caulfield

      Reply
  6. spacer Jared
    March 14, 2010 at 4:24 pm

    Just tried it.. no luck. It puts up a 404 error with that change if I try to go to the permalink without the index.php in there.

    I know absolutely nothing about coding, so please take this with a grain of salt, but I wonder if it has something to do with the “?p=$1 [NC,L]” text in that last line.

    It seems to me like the redirect is getting us to index.php, but isn’t pulling the correct post number from there, so it simply defaults back to index.php.

    I think I’m stuck with “partly” pretty permalinks, at least for the time being. It’s not the end of the world, but it would be nice to avoid it if I can.

    Thanks again for your response. I figured leaving the comments here would be best, just in case we discover a solution that can possibly help someone else with this issue in the future.

    Reply
    • spacer KyleCaulfield
      March 14, 2010 at 8:18 pm

      No problem Jared — I want to get this working for you! Can you verify the settings in wordpress? Go to Settings in wp-admin and then go to permalinks and let me know how you have that set up. PS the p=? is how wordpress normally finds what post you are looking for, so I think you are on the right track.

      Update:

      Can you try this in your httpd.conf file:

      RewriteBase /blog/
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule .* index.php [L]

      Reply
  7. spacer Jared
    March 15, 2010 at 6:43 pm

    Thank you for trying, but unfortunately, that didn’t work either. It still just redirects back to the blog’s home page.

    In fact, everything redirects back to the blog home page (even 404 errors). Clicking on any link in the blog simply reloads the blog’s default page (even though the address in the browser’s address bar changes).

    In my wordpress settings, I have to use /index.php/%postname%/ to make it work. Each time I test it, I remove “/index.php” so that it becomes simply: /%postname%/. But so far, we haven’t been able to make it work without keeping the “index.php” part in there.

    Reply
  8. spacer KyleCaulfield
    March 15, 2010 at 7:21 pm

    This is a shot in the dark, but you said you had /%postname%/ in your setttings… have you tried /%postname% ?

    Reply
  9. spacer Jared
    March 15, 2010 at 8:51 pm

    Yep, tried that one too. I’ve even tried it with a “.html” on the end.

    It works just fine so long as index.php is in the path, but fails whenever it’s missing.

    Reply
  10. spacer Jose
    March 18, 2010 at 7:28 pm

    I’m having the same exact problem Jared is having. Any ideas?

    Reply
  11. spacer Brent
    March 19, 2010 at 11:07 pm

    Any solutions if you have it hosted elswhere on IIS6, and not having access to the IIS control panel? Thanks!

    Reply
  12. spacer JC
    March 25, 2010 at 5:35 am

    Thanks, after weeks of mind-numbing dealings with Apache on Windows I finally did what you said and it works for my WordPress sites.

    I believe that some of the problems posted here are because they are not using WordPress since the matched pattern for what you write matches URL’s that contain index.php?p= .
    If any other application is being used you will have to modify the httpd.conf accordingly.

    If you want a particular pattern matched please email me at me@jcm7.com and I will try to help.

    Reply
  13. spacer Almeros
    March 26, 2010 at 8:39 am

    I had the same problem as Jared, and I found a fix for it (for WordPress 2.9.2 with ISAPI_Rewrite3), so I hope it helps you too Jared!


    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(index\.php)*(.*)$ index.php/$2 [NC,L]

    I will explain some more about it on my own blog which should soon be online (at time of writing this) at code.almeros.com.

    Reply
  14. spacer Jared
    March 26, 2010 at 8:21 pm

    Almeros,
    Thanks for posting. I *really* wanted it to work and was hoping it would. I went over the installation several times to make sure I was doing everything correctly and had typed it in right. I even cut-&-pasted your code to avoid errors, although I did have to add /blog to make sure it was referencing the correct index.php for my installation.

    But alas, it did not work. It creates a 404 error when I take index.php out of the permalink path. But here’s the interesting bit…the 404 is a new one. It’s the one that is part of my blog theme, NOT the normal generic 404 from Windows. So it’s something new. And the title bar says “Nothing found for Blog Index Php Blog”, which I’ve never seen before.

    I get the impression that we are really close to solving this, and that is has something to do with the syntax in that final line of code. But unfortunately, I’m just not smart enough to crack it. spacer

    Just in case it’s needed, here are all my “specs”:
    -Windows 2003 service pack 2 64 bit (IIS running in 32 bit mode)
    -MySQL 5.1
    -PHP 5.2.13
    -Wordpress 2.9.2

    I think that’s it, but let me know if you need anything else.

    Thanks guys for trying. I’m still keeping my fingers crossed.

    Reply
  15. spacer KyleCaulfield
    March 26, 2010 at 10:02 pm

    Jared — Stupid question, what version of WP are you running? Newest?

    Reply
  16. spacer Jared
    March 27, 2010 at 8:40 am

    See the last line of my previous comment: 2.9.2 Based on what I can see, I think that’s the newest non-beta release, but I could be wrong.

    What are you running?

    Reply
  17. spacer bobkknd
    March 27, 2010 at 8:39 pm

    E, ,,
    i like load~~~~

    Reply
  18. spacer S00p3r J35u5
    March 29, 2010 at 2:57 pm

    I love u blog.

    Reply
  19. spacer PlayTEX
    March 30, 2010 at 2:53 am

    This has been bugging me too for sometime too.

    Solution:-

    Place this in your .htaccess file or .conf file depending on the version of Helicon ISAPI rewrite you have installed. (.htaccess file to be located in “blog” subdirectory)

    Rule:-

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^blog/(.*)$ blog/index.php/$1 [NC,L]

    where “blog” is the subdirectory.

    Turn permalinks on and use either

    /%postname%/ for just a url or
    /%postname%.html for articles to end in .html i.e.

    Simple spacer

    Reply
  20. spacer Jared
    March 30, 2010 at 5:24 pm

    PlayTEX…nope. Same issue as the last time I tried. It 404′s on me, using the blog theme’s 404 page instead of the generic Windows one.

    (although with the spam in your comment, I probably should have guessed)

    There must be some setting in/on my system that apparently is different from the others who have gotten this to work. Such is the life of a Windows server, eh? spacer

    Reply
  21. spacer 21csm
    April 8, 2010 at 3:17 pm

    I have the same problem as Jared. And none of solutions above helped me either.

    WP settings are: /%year%/%monthnum%/%postname%/
    httpd.conf:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wp/index.php [L]

    And as the result I have:
    correct permalinks listed in browser’s address bar though every of them just leads to blog’s index page (with all posts listed).

    Can anyone advise with the correct settings?

    Reply
  22. spacer Almeros
    April 9, 2010 at 7:08 am

    Hi Jared and all others,

    After I posted my last comment I was happily installing everything on my live server just to get yet another 404 problem :S. This time it was IIS. Today I solved it and I wrote a blog article about all my fixes for the WordPress on IIS 404′s. Check it here: code.almeros.com/404-wordpress-permalinks-iis-with-isapi-rewrite

    I really hope you can find your solution there now, because I know how annoying this is spacer .

    Reply
  23. spacer 21csm
    April 11, 2010 at 1:28 pm

    Greetings to Jared and others.
    I solved IIS / mod_rewrite problem for my site but without using Helicon ISAPI_Rewrite Lite. This particular module did not work before I put special PHP-hacks in wp-settings.php (like statement $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; in the very beginning of file) and even then I couldn’t fully adjust it.
    I overcome Rewrite problem by using Ionics Isapi Rewrite Filter. It did not require anything to be patched in WP though I had to create rewrite rule for every special case.
    You can see my configuration file shared.
    Maybe it’s a kind of brute force method but it worked for me.

    Reply
  24. spacer PlayTEX
    April 13, 2010 at 12:28 am

    Hey,
    If you are getting 404 errors have you actually checked that the rewrite is occurring?

    I initially had this error and had to go through the Helicon log files to spot it… on doing so I reconfigured the site settings within plesk and it worked.

    P.S last post only contained a link for reference to my blog that works… not spam

    Reply
  25. spacer Rafael M
    April 26, 2010 at 6:59 am

    What about those who do not have access to the IIS in their hosting?
    I cannot even start by installing ISAPI_Rewrite Lite.
    Any suggestions?

    Reply
  26. spacer Max
    April 27, 2010 at 12:48 pm

    Lars CMS Meyer said “…this is all you need. 5 minutes after finding this guide”

    Yes i agree. I’d say it took me about 5 minutes to get Permalinks working in WordPress.. using ISAPI_Rewrite3 on IIS 6.0

    Thanks for posting this – very useful !

    Reply
  27. spacer Max
    April 27, 2010 at 1:03 pm

    update… right after fixing the Permalinks in a WordPress application, (as above) i spent the next 5 minutes undoing it all again as it trashed all of the other sites on the same server spacer

    Not sure what to do now? jump off the nearest high building?

    Reply
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.