Keyboard Face

when you find QWERTY imprinted on your cheek - it's time to go to bed.

Tags

asp CSS css menus dreamweaver flash gallery2 hosting iis7 Javascript jquery jquery ui left mac mssql os9 php printer rdp SEO sql sql server windows wordpress

WordPress PermaLinks in IIS without the mod_rewrite

May 21, 2006 by Tom 171 Comments

In a previous post, I mentioned that I was investigating a way to use real permalinks without using any of the ISAPI mod_rewrite dlls. For the uninitiated, mod_rewrite is not natively supported in IIS (Window’s server), and to get the same functionality, you have to install separate programs. I’ve done that and that is how this blog has survived on a Windows server for the past year or so.

I was convinced that needn’t be the case though. There must be a way to have permalinks without having to install a whole separate mod_rewrite program (or extension). I detailed my plan in this post.

Well, I finally got around to it – and the plan worked!

Here’s the gist of it. It uses custom 404 redirect to send all “Page Not Found” errors to a script that reads a bunch of regular expressions (don’t worry, you don’t have learn regular expressions to use this) and figures out what page to feed back.

Now, some people may find my solution a bit odd considering it is written in ASP. You used ASP to extend wordpress?? Yes, and it worked :).

More detailed instructions, and a link to the needed files are located here:

WordPress Permalinks in IIS

Filed Under: Installing Wordpress

Comments

  1. Nick Dunn says

    May 25, 2006 at 6:54 am

    Firstly, many thanks for documenting your process. I have just written a similar custom 404 page, but slightly less elegantly than yours. One problem. There’s a textbox in the Admin panel with any rewrite rules in it. Your instructions say it should be beneath the “Update permalink structure” button, but there’s nothing.

    Is this a particular plugin/option I need to enable? I have set $use_verbose_rules = true.

  2. Michael Walsh says

    May 25, 2006 at 8:24 am

    This doesn’t seem to be working for me, I can’t see a textarea box with all of the ReWriteRules? I’m runnning WordPress 2.0.2

    I’m setting this up in a subdirectory if that makes any difference, so it’s http://www.example.com/blog/

  3. Tom says

    May 25, 2006 at 9:13 am

    I ran into the same thing when I was trying to install it on WordPress 2.0.2. In this new version, it doesn’t show the ReWrite rules when you have the “Common Options” set to anything but “Custom”. Select “Custom”, enter in a permalink structure and it the box with the rules in it should show up.

    Mine is:

    /archives/%year%/%monthnum%/%day%/%postname%/

  4. Tom says

    May 25, 2006 at 9:16 am

    The sub directory may make a difference. I haven’t tested it out in that situation yet. You may have to modify the rewrite rules to add your sub directory in front of them like so:

    Before:

    RewriteRule ^archives/author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L]
    RewriteRule ^archives/author/([^/]+)/page/?([0-9]{1,})/?$ /index.php?author_name=$1&paged=$2 [QSA,L]
    RewriteRule ^archives/author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L]
    RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]

    After

    RewriteRule ^yoursubdirectory/archives/author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ yoursubdirectory/index.php?author_name=$1&feed=$2 [QSA,L]

    RewriteRule ^yoursubdirectory/archives/author/([^/]+)/page/?([0-9]{1,})/?$ /index.php?author_name=$1&paged=$2 [QSA,L]
    RewriteRule ^archives/author/([^/]+)/?$ yoursubdirectory/index.php?author_name=$1 [QSA,L]

  5. Nick Dunn says

    May 25, 2006 at 10:14 am

    Cool, it’s working. Ish.

    To get the rewrite rules up, I had to edit the “Blog address (URI)” and add a subdirectory, e.g. “myblog.com” to “myblog.com/test/”. The box then showed up on the Permalinks page. I then did a find/replace, removing all “/test” strings, and put my “Blog address (URI)” back to the original URL.

    It all seems to be working except for actually viewing a post itself. For example, my permalist structure is:

    /%year%/%monthnum%/%postname%/

    When viewing a post page itself, a quick debug of the 404 handler shows the following string for the URL variable:

    /index.php?year=[yyy]&monthnum=[mm][post-title]

    i.e. the post title and month are concatenated.

    I’m trying to decipher the list of rewrite rules, but finding it difficult to debug.

  6. Tom says

    May 25, 2006 at 10:19 am

    Can you give me an example of a ReWrite rule you are using?

  7. Nick Dunn says

    May 25, 2006 at 10:22 am

    Sure. I *think* this might be the offending rule. Taken straight from the WP output.

    RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2 [QSA,L]

  8. Tom says

    May 25, 2006 at 10:27 am

    The rule you gave me is missing the “PostName” variable. Originally, I was figuring we wouldn’t have to decipher regular expressions to get it working.

    From your previous post, it looks like it’s missing this string here: &name=[post-title].

    You wrote that it is resolving to: /index.php?year=[yyy]&monthnum=[mm][post-title]

    I would try starting over (rather than trying to debug the regular expressions). Just try changing the permalink structure (make sure it’s set to custom), and re uploading the htaccess.txt.

  9. Nick Dunn says

    May 25, 2006 at 10:43 am

    Yep, it’s missing name=[title] but I can’t for life of me see why that rule isn’t being written by WP, especially when it’s in my permalink structure. Never mind, it’s not too tricky to modify the expressions manually to include this.

    I shouldn’t be wasting time on this at the moment (Uni finals tomorrow!) so will revisit this discussion in a few weeks when I have more time.

    Once again, thanks for the well thought out script, and taking the time to help πŸ™‚

  10. Tom says

    May 25, 2006 at 10:45 am

    No problem. Best of luck on the finals.

  11. Oman says

    June 5, 2006 at 8:58 pm

    I tried installing it, and it didn’t work. I am running on a Linux server so I don’t know if that had and effect. If you can help me fix this problem I would greatly appreciate it.

  12. Tom says

    June 7, 2006 at 1:31 pm

    Oman – The modification was designed for use on a Windows server. IIS (Internet Information Services) is Microsoft’s web server software. It also relies on ASP, a programming language specific to Windows.

    With Linux, you shouldn’t even need this though. You should be able to just copy/paste the rewrite rules into your .htaccess file and it should work.

  13. Larry says

    June 14, 2006 at 10:05 am

    Started getting WP setup and customized late last week on IIS 5. So far, I’m happy with my progress. I stumbled upon your site while trying to figure out my 404 issues. WP is installed on the root of my site.

    When trying to test my 404 it seems as though I’m being redirected to WP’s index.php.

    Any thoughts or suggestions?

  14. Tom says

    June 15, 2006 at 2:55 pm

    Larry – What do you mean by testing your 404?

    Are you trying to set up a custom error page in addition to this solution? If so, you need to edit a variable in the file errorpage.asp.

    At the very top of the file it says:


    Actual404 = "/"

    You would change that to be whatever your real 404 page is – for instance, you could have it redirect to “/404Error.html”

  15. Chad says

    June 19, 2006 at 7:12 am

    I’m pretty new to this stuff, and I’m having some trouble with this little redirect bugger. I have followed your instructions but I’m still getting a page that says “The system cannot find the file specified.”

    The only way my permalink structure works right is when I’m set to: /blog/?p=123.

  16. Don West says

    June 22, 2006 at 8:43 am

    Hi,
    Great solution! Many many thanks for developing it!
    I’ve just installed the iis rewrite and it seems to work fine with one exception.

    If you go to my site and click the “quick sketches” category, as expected you’ll see the pretty permalink in the url:

    http://www.idleminutes.com/archives/category/quick-sketches/

    However, if you then scroll down to the end of the last post and click the “older posts” navigation link, the URL changes as follows:

    http://www.idleminutes.com/index.php?category_name=quick-sketches/&paged=2

    Is that the correct behavior?

    Each individual post’s permalink is still a pretty permalink. I’m just wondering if the URL should be as well.

    Thanks!

  17. Tom says

    June 22, 2006 at 10:28 am

    First off, I thought I should note that Chad figured out the problem with his script – it had to do with where php was installed on the system. The system cannot find the file specified is a php error, not a wordpress error.

    Secondly, Don – Thanks for pointing that out. It does the same thing on my blog unfortunately. I think it has to do with the way the script gets the information to display (it actually acts like a web browser, fetches the page using the index.php?category_name=…, and then displays it under the permalink structure).

    This is just me guessing, but I think that because we get the page that way, wordpress thinks we’re not using ther permalink structure and would therefore like our links to be the standard.

    You may be able to change this by editing your template, but I can’t help you much there.

    So I guess the short answer to your questions is – sorry! πŸ™

    If you figure out a solution let me know and I’ll include it in the script.

  18. Don says

    June 22, 2006 at 11:10 am

    Thanks Tom,
    When you say I might be able to edit my template, what part of the template would I would investigate?

  19. Don says

    June 22, 2006 at 11:16 am

    Tom,
    One other thing, if you click any archive post, rather than categories, you’ll get a horizontal nav link at the top of the post.
    Those nav links display the proper URL (rewritten).
    Any insight on why that works and the other ones don’t?

  20. Tom says

    June 22, 2006 at 11:23 am

    I looked at my own template and this is what I found in archive.php:


    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div>
    <div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?></div>
    </div>

    That led me to think that, although you could fix it in the template area, you may want to fix it in the function itself. The posts_nav_link() function is located in wp-includes/template-functions-links.php.

    I don’t have the time at the moment to go through it fully myself, but if you find anything, let me know.

    Thanks!
    Tom

  21. Tom says

    June 22, 2006 at 11:25 am

    I think that has to do with the function I mentioned. It may be that the different pages you are referring to are using different functions for their nav_links, though. Take a look at the template-functions-links.php, it may give you some insight.

  22. Darryl says

    June 27, 2006 at 7:35 pm

    The instructions in your “WordPress Permalinks in IIS” are great, but I’m just trying to figure out how to apply them to the control panel at my hosting site. The only thing that comes close is an option to Redirect URL, with the following options (_____________ indicates a text box for me to fill in):

    1. Redirect from http://www.example.com/_________________

    2. To http:// or ftp:// or https:// _________________

    3. The client will be sent to (select one from below):
    – The exact URL entered above
    – A directory below this one
    – A permanent redirection for this resource

    Any thoughts on what I fill in for 1 and 2, and which option I select for 3?

    Any assistance would be greatly appreciated πŸ™‚

  23. Tom says

    June 27, 2006 at 11:24 pm

    Hey Darryl,

    First off, I took a look at your blog – You’ve got a great design there. Nice use of AJAX too.

    As far as your question goes, I don’t think you’re in the right place. You want access to a “Custom 404 Error Page”. The panel you described has to do with redirecting to another site or URL on your site.

    Contact your host and see if they support custom error pages. They should be able to. If they don’t have it in their control panel, you can call them and give them the instructions to set the custom 404 error page to “/errorpage.asp” and make sure it’s set to URL, not FILE.

  24. Darryl says

    June 28, 2006 at 1:11 pm

    Tom,
    Thanks for that. You’re right – I was very much looking in the wrong place. There’s an option in the Control Panel for “Error”. I went in there, set the 404 page to be redirected to /errorpage.asp, and everything worked beautifully.

    It was such a relief. I have been trying so many things over the past couple of days, and this is the only spot I found this particular solution of yours. You’re a champ, Tom!

  25. Dcrad says

    July 7, 2006 at 4:32 am

    @Darryl – it sounds like you have the same control panel as me. I’ve been unable to get it working, you say you set 404to be redirected to /errorpage.asp – my hosting doesnt allow me to do that as it seems to not like the “/” – it allows me to use just “errorpage.asp” – but I just a standard 404 type message when I click on my permalinks.

    Any ideas?

  26. Dcrad says

    July 7, 2006 at 4:47 am

    Sorry thought I better clarify things a bit in relation to my last post….

    I get “HTTP/1.1 404 Object not found” when clicking my permalinks. But what i notice is that regardless of the url given for the errorpage.asp I always get this. I’ve even tried setting my index.php as the 404 page but always get this problem.

    Any ideas?

  27. dave sweet says

    July 10, 2006 at 4:58 pm

    When I enable this it works as advertised, but it substitutes ? for spaces throughout the text of my entries. If I go back to a default permalink structure, the ?’s go away. Any thoughts on why this would happen?

  28. Tom says

    July 11, 2006 at 4:51 pm

    Dave –

    I looked at another site that I have this solution installed on and I found that it was doing the same thing as yours (putting ?s in for spaces)

    It has to do with the Charset the browser is using to interpret the page. That setting is being wiped out in the transition.

    We can, however, set it manually within the page itself. In errorpage.asp add the following line:

    Response.Charset = "ISO-8859-1"

    This should be entered right before these two lines:

    Response.Write ReturnPage(Path)
    Response.End()

    This fixed it for me. I am debating whether to put it in the original download. My thought is that not everyone will be using that Charset.

  29. Matthew says

    July 13, 2006 at 1:45 am

    Works great! The only hickup I had was that I had a htm 404 page before and this was cached in my browser which seemed all wasnt working. A CTRL+F5 fixed the issue πŸ™‚

    Nice work!

  30. modernape says

    July 13, 2006 at 2:28 pm

    Hiya,

    I installed errorpage.asp and htacess.php, on the same directory that wp is on, a windows server, but I get this error message in my browser window when I click on a permalink, even though it looks fine in the status bar. –
    ”
    Microsoft VBScript runtime error ‘800a139d’

    Invalid range in character set

    /alcohol-drugs/errorpage.asp, line 84 ”

    I’ve set up the 404 redirect as per instructions too, so I’m not sure what else to do?

    Thanks very much for your help
    Modernape πŸ™‚

  31. Tom says

    July 13, 2006 at 4:25 pm

    Modernape – what is your site?

  32. modernape says

    July 15, 2006 at 7:56 am

    Hi Tom, my site is –
    http://www.brighteyecounselling.co.uk/alcohol-drugs/

    (the alcohol-drugs directory is WP), but as it wasn’t working I’ve reset the 404 page and the WP permalink format back to normal!
    Any ideas what was wrong? Or do I need to set it all up again?

    Thanks

  33. Tom says

    July 15, 2006 at 11:28 am

    I’m not sure – what was your permalink structure?

  34. modernape says

    July 16, 2006 at 12:29 pm

    I had permalinks exactly as you suggested.

  35. Chris says

    July 18, 2006 at 8:50 am

    I’ve made the changes and everything is working… except for the actual archive page. The form for the comments is not displayed at all.

    However, if we change the permalink to something else, say, /index.php/%year%/%monthnum%/%day%/%postname%/ — then the comments form does appear.

    As soon as I remove “/index.php”, again, the comments form disappears. Any idea what may be wrong?

  36. Tom says

    July 18, 2006 at 1:26 pm

    Chris – I had a similar problem recently on this site. I didn\’t have the permalink structure of /index.php/…, but the actual post pages weren\’t working. They were directing to archive pages – for instance the following link would point to the archive page for May 21st.

    http://www.keyboardface.com/archives/2006/05/21/wordpress-permalinks-in-iis-without-the-mod_rewrite/

    It was, in effect, ignoring the last part of the url. This was because of the order the script parsed the rules. I put out a new version of the script as of a couple of weeks ago. You may try getting the most recent version of errorpage.asp.

    If you have the most recent version, I\’m not sure what to say. Maybe, try and take the index.php out of the permalink structure?

    If you\’re determined to keep the index.php in the structure, you can try this other solution:

    http://blog.taragana.com/index.php/archive/wordpress-tip-on-permalink-options/

  37. FA says

    July 25, 2006 at 11:46 am

    I’ve been trying to get this solution to work as it seems perfect. However, after following the instructions, all I get is a hung site. The home page loads, but articles don’t regardless of what permalink structure I choose. The browser just sits there with the status indicator spinning at the top-right. Accessing htaccess.php directly also hangs.

    Any ideas?

  38. Tom says

    July 25, 2006 at 2:50 pm

    It would seem that the problem is coming from htaccess.php then. You can try switching it from using htaccess.php to htaccess.txt. Look at the very last section of the instructions page, it should help.

  39. FA says

    July 25, 2006 at 3:28 pm

    Tom,

    I tried switching to htaccess.txt and that didn’t work. However, I did find some info that fixed my problem. I needed to create a php.ini file and included these lines:

    cgi.fix_pathinfo = 1
    cgi.force_redirect = 0

    My PHP skills are a little weak so I don’t know exactly what the above does, but it came from the WordPress Codex and it works. I now have rewrites working.

    My next problem is now when a user posts comments, they are always directed to the home page rather than to the post they replied to. I’m pretty sure this has to do with the threaded comments or subscribe to comments plug-ins I use.

  40. Shell says

    July 27, 2006 at 7:24 pm

    I have followed your instructions to the letter and get this message on every page but the home page: The system cannot find the file specified.

    Everything is in the root folder and I have added the php.ini file as instructed. Not sure what else to try.

  41. Tom says

    July 28, 2006 at 9:40 am

    Shell –

    It most likely is one of two things:

    1. php.ini is located in the wrong place.

    2. there is something wrong with the regular expressions in htaccess.php or htaccess.txt. To debug it, I’d set the script to use htaccess.txt and then play around with the regular expressions to see which ones it was using.

  42. Stefan says

    July 31, 2006 at 4:11 am

    Hi Tom,
    i tried a lot but it doesnt work. When i use the php.ini file all works fine with the /index.php in the url but without /index.php it will not works. what could it be? something i have write down to the htaccess files?

    thanks a lot.

    Stefan

  43. Tom says

    August 1, 2006 at 11:00 am

    Thanks to Stefan. He pointed out a good alternative to the solution posted here. Here it is:

    http://www.simmonsconsulting.com/wordpress/?p=204

    you only have to create a new file, for example: wp-iis.php and put following in

    < ?php $my_wp_url = "http://" . $_SERVER['SERVER_NAME'] . "/wordpress"; $_SERVER['REQUEST_URI'] = substr($_SERVER['QUERY_STRING'], strpos($_SERVER['QUERY_STRING'], $my_wp_url)+strlen($my_wp_url)); $_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI']; include('index.php'); ?>

    save the file in your wordpress directory and open your iis-center. and take a change in the domain where your wp installation at.

  44. Mike says

    August 3, 2006 at 12:06 am

    Works great – thanks!

  45. Julio says

    August 10, 2006 at 2:06 pm

    I’m having troubles with international characters.
    Here is an example:
    http://www.juliozuniga.com/blog/archives/2006/08/07/hola-mundo/
    What can i do?
    Thanks in advance

  46. Tom says

    August 11, 2006 at 11:08 am

    Julio –
    It has to do with the character set the ASP page sends to the browser. You can try changing the character set to be: “ISO-8859-1”. If that doesn’t work, try other character sets until you get the result you’re looking for. Here’s how to do it:

    In errorpage.asp add the following line:

    Response.Charset = "ISO-8859-1"

    This should be entered right before these two lines:


    Response.Write ReturnPage(Path)
    Response.End()

  47. Sara says

    August 16, 2006 at 2:12 pm

    I’m working on a site for a client, that is installed on an IIS server.

    I installed errorpage.asp and htaccess.php into my wordpress folder, and changed the setting for the 404 page for my server to wp/errorpage.asp .

    I set my permalinks to /%postname%/ and didn’t set any permaliniking rules for a “category base”.

    Unfortunately, when I try to click on or enter a permalink, rather than going to the page I’ve chosen, my browser pops up a screen telling me I’m trying to access a binary file and asking me what I want to do with it. (there are no auto-generated permalinks on the front page of the site, but if you click on any of the links at the top of the screen, and then click on any of the sidebar links on any of those inside pages, you’ll see the behavior I’m talking about).

    I tried replacing htaccess.php with htaccess.txt, which did not change the situation.

    I also tried several different custom and standard permalink options, all to no avail — the problem stays the same each time.

    Any advice? Thanks very much!

    -Sara

  48. Antoine Khater says

    August 17, 2006 at 5:40 am

    First let me thank you for the great tip, I really like it, Now i am facing 2 problems and I’d really apreciate your help

    Please open http://www.adidap.com and http://www.adidap.com/page/2 in 2 different browser sesssions
    1) The Β© in main page is looking well, in page 2 it is showing as a ? (this was solved by adding Response.Charset = “ISO-8859-1”
    2) The layout in page 2 is shifted πŸ™ the sidebar is not at its correct place

    thanks

Newer Comments »

Leave a Reply Cancel reply

Your email address will not be published.

Pages

  • About Me
  • WordPress Permalinks in IIS using Custom 404 Redirect

Archives

  • May 2019
  • February 2019
  • January 2018
  • May 2016
  • April 2016
  • December 2015
  • November 2015
  • May 2015
  • April 2015
  • January 2013
  • March 2012
  • February 2012
  • December 2011
  • September 2011
  • August 2011
  • November 2010
  • October 2010
  • June 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • September 2009
  • August 2009
  • July 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • November 2008
  • September 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • December 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • January 2007
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • May 2005

ASP.NET Resources

  • Keven Roth’s Code Library
  • Lemon Law

Blogroll

  • Arin Morfopoulos
  • Jamie
  • Physical Therapists

Code Search Engines

  • Koders
  • Krugle

CSS & Design Resources

  • CSS Basics

Other

  • Amazon
  • Car Repair Questions
  • Cool Quizzes
  • Delphi LA
  • Physical Therapy Clinic Directory
  • Quickbooks Questions
  • Secret Santa Game

Site\'s I\'ve Designed or Helped With

  • Area Rugs
  • Dental Implants
  • Dental Website Design
  • FHA Loans
  • Secret Santa Gift Ideas