Keyboard Face
msgbartop
when you find QWERTY imprinted on your cheek - it’s time to go to bed.
msgbarbottom

21 May 06 Wordpress PermaLinks in IIS without the mod_rewrite

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

Share and Enjoy:
  • del.icio.us
  • digg
  • Furl
  • NewsVine
  • RawSugar
  • Reddit
  • Spurl
  • YahooMyWeb


Reader's Comments

  1. |

    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. |

    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. |

    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. |

    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. |

    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. |

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

  7. |

    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. |

    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. |

    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. |

    No problem. Best of luck on the finals.

  11. |

    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. |

    [...] s idea over at Keyboard Face.
    This entry was [...]

  13. |

    [...] heavily customised version of Tom’s idea over at Keyboard Face. [...]

  14. |

    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.

  15. |

    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?

  16. |

    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”

  17. |

    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.

  18. |

    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!

  19. |

    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.

  20. |

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

  21. |

    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?

  22. |

    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

  23. |

    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.

  24. |

    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 :)

  25. |

    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.

  26. |

    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!

  27. |

    @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?

  28. |

    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?

  29. |

    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?

  30. |

    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.

  31. |

    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!

  32. |

    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 :)

  33. |

    Modernape - what is your site?

  34. |

    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

  35. |

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

  36. |

    I had permalinks exactly as you suggested.

  37. |

    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?

  38. |

    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/

  39. |

    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?

  40. |

    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.

  41. |

    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.

  42. |

    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.

  43. |

    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.

  44. |

    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

  45. |

    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.

  46. |

    Works great - thanks!

  47. |

    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

  48. |

    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()

  49. |

    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

  50. |

    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

  51. |

    Thanks for the great tip, I am having a problem
    please try to open http://www.adidap.com and http://www.adidap.com/page/2 and notice how the sidebar is shifted down

    Thanks

  52. |

    When I am using this, even when I am logged on, I can only see the “admin website” link if i am on the root page, in all other pages, it is replaced by the “login” botton

  53. |

    I am really sorry for the multiple posts :( I kept on refreshig the page but they didn’t show up

  54. |

    Hello! First, thank you for providing this. I’m sure it’ll help with the search engines.

    I have one minor problem. After installing, I noticed the links on the right hand side are bold (sometimes).

    It seems to happen 100% of the time with the default/main page and on some of the pages that show up when I click a tag.

    What’s the first thing I need to do to solve this?

    Thank you. =)

  55. |

    A great workaround, but took time to get working. I was installing Wordpress 2.0.4 on a hosted Windows 2000 server, and followed all the installation steps as you give. But normal 404 error page kept reappearing, even though I had entered hoster control panel and configured the custom error message to errorpage.asp, and it confirmed the change. So I contacted the hoster, said the custom error wasn’t working - they then switched on.

    So my point is: even if you think the host control panel confirms the custom error page, you may have to ask them to implement it before it works.

    Otherwise - great solution to the problem!

  56. |

    Hi, great little hack you got going here. One problem, not quite sure what to do with it. I got the script working great, but the theme I have selected only applies to the root index. If I go to one of the sub pages/categories it uses the original wordpress theme. Is there anyway to combat this besides placing the new theme into the original wordpress directory? You can see what I’m talking about at http://www.bluesdragon.com/blog/. Any help would be appreciated. Thanks.

    Zach

  57. |

    I’m not sure what you are talking about in terms of the themes, but it appears that there is something weird with the way the script is interpreting your permalink structure. It looks like it is directing all requests to return the home page, not the individual post pages or the archives.

    Have you tried it without the permalinks to make sure it works that way?

    Have you tried a different permalink structure?

  58. |

    Yeah, nevermind about the themes. Something funky was going on there. I have the Dynamic = False , and that way the urls work right but don’t point to the right pages (like you said. If it’s set to True it doesn’t work, it just redirects to the blog’s homepage. Have any suggestions on what I can try to fix it?

  59. |

    Zach,

    Sorry for not responding sooner - I hadn’t noticed you replied when you did.

    When you set it to Dynamic = False, did you also upload the htaccess.txt?

  60. |

    Hi,
    On http://blog.a1teamusatv.com I’m getting this error:
    msxml3.dll error ‘800c0005′
    The system cannot locate the resource specified.
    /errorpage.asp, line 141

    I read that might be cause of the server - MSXML version or something about firewall but I’m not sure. Can you indicate me any possible solution?

    Thanks in advance.

  61. |

    Vialuna,

    I’m not sure what would be causing that. You can check to make sure that it is asking for the correct page by inserting this line


    response.write (SiteName & URL)
    response.end()

    This should be entered right above these lines:


    If Left(URL, 1) = "/" Then
    xml.Open "GET", "http://" & SiteName & URL, False

    If that shows you an empty string then you know it’s occurring because of that. If it gives you anything else, there is something wrong with your firewall or xmlhttp version.

  62. |

    I put those lines and now shows: domain.com/htaccess.php
    you can check http://blog.a1teamusatv.com/ clicking on that 1st post.

    Where do you think could be the problem?

    Thanks for your help.

  63. |

    Thanks, the problem isn’t with the rules then. It’s a problem with the way the XMLHTTP object or a firewall on the server.

    Unfortunately, I don’t have any good advice on how to fix either of those problems. The one last thing you can try (I’m not very hopefull of it working though) is to Find/Replace all instances of “Microsoft.XMLHTTP” to “MSXML2.ServerXMLHTTP”.

  64. |

    Hello!

    I’m trying to install your solution in my WordPress blog but i can’t do run it!!

    My blog is: http://blog.jatubio.com
    I will had configured permalinks in wordpress same of you:

    I will have trying to use ‘Dynamic Rules’ but htaccess.php do not’t return any text.

    For ‘Static Rules’ i will have removed the first and last lines of htaccess.txt: “” and “” and it’s works ok.

    Any idea for work with Dynamic??

    Thanks you in advance.

    And many thanks for this great works!!

  65. |

    Hi Jatubio,

    I took a look at your htaccess.php file on your server. It gave me this error:

    Fatal error: Call to undefined function: mod_rewrite_rules()

    mod_rewrite_rules() is supposed to be wordpress’ built in function that returns the rules. Rather than try and debug why that’s not working, you can just get the appropriate rules by going in to wordpress’ admin section under permalinks it says something like this:

    “If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all.”

    Copy and paste the entire thing into your htaccess.txt and set the script to static rather than dynamic. That may work. Otherwise, you might want to try a different workaround.

    Best,
    Tom

  66. |

    Hi all,

    Forst of all thanks for the script!

    I kept on getting this error:

    Microsoft VBScript runtime error '800a0005'
    Invalid procedure call or argument: 'Left'
    /errorpage.asp, line 179

    After debugging I found out that the variable Start needed to be initialised to 1 in the function AddCredits:

    Function AddCredits(PageHTML)
    Start=1

    Now it works as a charm. Thanks!

  67. |

    Thanks! I’ve added that line to the main download.

  68. |

    Hi All,

    I have problem with the solution. I installed and configured everything as described. However if I click on a page or post I always get the front page. You can check my temporary site at http://madfie.hu.anaxanet.com/.

    Do you have any idea what can be the solution?

    Thanks in advance,
    Domokos

  69. |

    Hi Domokos,

    Generally, what that means is that the rules that are in the htaccess.txt or htaccess.php file are not correct. Are you using htaccess.php or htaccess.txt (static or dynamic?).

    If you reupload htaccess.php I might be able to help.

    Best,
    Tom

  70. |

    Hi,Tom

    I tried you solutions, Thank you very much ,but I meet 2 problem.

    1: my web site is in Chinese, double-byte, and if use your solution, the Chinese text will change to ????????, question marks.I tried to add

    Response . Charset = “UTF-8″ or “GB2312″ or other charset,

    but it dosen’t work.

    2.I use your static soluton now, because dynamic solution seems fail.
    but, now, I must access my site with http://learning.artech.cn/index.php, can not omitt the “/index.php”

    Could you tell me how to resolve the two problems?

    Thank you very much!

    (Now, i have uninstalled the solution for normal access)

  71. |

    Hi Chance,

    Thanks for letting me know about these problems. I haven’t tried it out with Chinese characters before. I looked up what the Charset should be for Chinese and it is: big5.

    Here’s the link I used to find that out:
    http://a4esl.org/c/charset.html

    So, in your code use:
    Response.Charset = "big5"

    I’m glad you figured out how to use the static solution. I have a feeling (I haven’t tried this out yet) that the dynamic permalink rules might not work with the latest release of Wordpress (2.0.4). If anyone knows for sure, please let me know.

    What happens when you omit the “/index.php”?

    Thanks,

    Tom

  72. |

    thank you for your reply!

    for 1st question:

    The “big5″ is another Chinese charset, which is used in Taiwan, “gb2312″ is used in mainland of China.

    but both of them fail, all Chinese text was replaced by question marks as ????????.

    The home page “index.php” is correct, but all other linked pages can not dislpay Chinese Text

    for 2nd question:
    if directly access http://learning.artech.cn, the web page is blank, there is not any thing in it. if access http://learning.artech.cn/index.php ,the home page is OK!

    I am using the 2.0.4 version. is this cause the problem?

    thank you very much!

    Chance

  73. |

    hi,Tom!

    I have almost resolve the problem.

    Now, everything seems good except that the statice “Pages” can not be correctly linked.

    Just like your blog, the page “About me” links to “http://www.keyboardface.com/about/” , but in my blog it redirect to 404page. I guess i must add some rules in htaccess.txt?

    Thank you very much!

    Chance

  74. |

    hi, Tom.

    This my third reply to you !

    I must tell you the good news! I have make it OK!

    about the Chinese text, I add a line at the beginning of errorpage.asp, it’s OK!

    and about the “Pages”, I find the secret of (about) and (iis_ermalink) in htaccess.txt, I replace them with my own strings, it’s OK!

    thank you very much! I’m very happy!

    there is the last question, to you mind, do you think this operation will lower the response speed of this web pages?

    than you!

  75. |

    Hi Chance,

    That’s great to hear that you got it working! What was the line that you added to the beginning of the page that made it work with Chinese?

    As far as the lower response speed of the web pages. It might slow it a tiny bit because it has to initiate a separate HTTP request for the page rather than just rewriting the URL. Here’s the post that goes over the idea.

    Thanks!
    Tom

  76. |

    How did Chad fix the php error, The system cannot find the file specified error, he was having? I am having the same error and I just can’t find the fix. I have setup a virtual directory for my blog on my dedicated Windows 2003 Server. Thanks for any help you can give me.

  77. |

    Hi Tom,

    I have the same problem as Domokos (17/10/06). I tried Dynamic (htaccess.php) and was only able to return the home page, I changed errorpage.asp to False to use htaccess.txt and receive the same error. My control panel is Helm. For custom error pages I can only edit the page location of the file, I can’t select whether it is a file, URL or default. My error page location is /errorpage.asp I’m clueless.

    Gary

  78. |

    Hi, Tom,

    the line at the beginning of error page I mentioned above is “[%@codepage=936%],
    yesterday the code was removed in my post. so I use [] replace .

    Thank you very much!

  79. |

    hello Tom,

    Here I have a new problem to ask for help to you!

    I use a tag(keyword) plugin of wordpress, so I added a new line in htacess.txt as :

    RewriteRule ^tag/(.+)/?$ /index.php?tag=$1 [QSA,L]

    if the tag is english , it works well.

    but the problem is that if the tag is Chinese it will be convert to UTF-8 then the URL is like http://…../tag/%E5%BD%A2 ,then it can not find the post.

    but I tried http://…../?tag=%E5%BD%A2 , it’s OK.

    that is to say the course of converting is not correct for the string “%E5%BD%A2″?

    I don’t know what’s the reason ,and how to make my tags support Chinese.

    maybe the new rewrite rule I added is wrong?

    thank you very much!

  80. |

    Hi all,

    Sorry for the delay in replying to your comments. It’s been a busy week over here.

    First off, Jared, Chad’s problem was that his php.ini file was in the wrong folder. The system cannot find the file specified error, is a generic php error and can be caused by any number of errors, though.

    Gary, I think there is something with Wordpress 2.0.4 where it’s not giving the correct rewrite rules to the plugin. I have yet to test this. You can try using htaccess.txt instead of htaccess.php.

    Chance, try this rule:

    ^tag/([^/]+)/?$ /index.php?tag=$1 [QSA,L]

    Let me know if it works.

    Thanks,
    Tom

  81. |

    Tom,

    I created a “php.ini” file with the following content:
    cgi.fix_pathinfo = 1
    cgi.force_redirect = 0

    Uploaded the file to the root of my blog and now have permalinks working.

    Is there any method of removing the “index.php” in the permalinks output?

    Gary

  82. |

    I’m glad you got the php.ini file working. This solution should be giving you permalinks without the /index.php/categoryname…/ structure. I suspect you may be using a different solution if you have that structure.

    If you are using this solution, then you should be able to change your permalink structure within wordpress and it will just work.

    One tip for you. I took a look at your blog and it takes a really long time to load. The reason is you have the Google Maps code included on all of the pages of your blog, not just the ones that have Google Maps on them. You should be able to add the appropriate code, just on the select pages that need them.

    Best,

    Tom

  83. |

    I modified the htaccess.txt according to your code, but the result is same as what I described before. it only works to english tags, but not to unicoded tags,such as “%E5%BD%A2″.

    I don’t what is key reason of this problem.

    Thank you very much!

    Chance

  84. |

    Hi, Tom,

    I found there is really a problem.

    If the request includes non-english encoded text, including querystring and form, it can not transfer to the errorpage.asp.

    I did a test, that I added a line to directly write the querystring at the beginning of errorpage.asp, I found the querystring had been changed. the non-engish words had been replaced by “?”.

    I guess because IIS get the request, and find that the page dose not exist, so redirect to the errorpage.asp, but in the course, querystring has been decoded as default codepage, so that non-english text will be translated into “?”, and then errorpage.asp can not do rightly.

    So, could you have some good way to make IIS totally “copy” querystring to errorpage.asp, so that errorpage.asp can decoded the request according to the correct codepage.

    thank you!

  85. |

    Hi Tom, I am still experiencing difficulties on my site.

    I still can not get this to work without including “index.php” as part of the permalink. I have tries both the “php” and “txt” options without success. I am using the default files from the download.

    I am also experiencing a problem with the navigation links with “category.php”. Page 1 displays correctly, but if there are more than 5 posts in a category, Page 2 displays the second page of ALL posts, not just the posts of the current category.

    I suspect this problem has something to do with the first problem as it is obviously using “index.php” instead of “category.php” to retrieve the post excerpts.

    I know the google maps plugin is a bit cumbersome, but I would like to get these issues resolved before moving on to that one.

    Any chance you could take a further look.

    Thanks in anticipation.

    Gary

  86. |

    Hi Tom,

    Finally got it all working!

    Regards

    Gary

  87. |

    Dear Tom,
    Thank you for the very innovative approach to the IIS url rewrite problem.
    I am actually using WordPress Multi-user, mu.wordpress.org

    Your solution works with main user, however, when trying to access other newly created blogs, the parserules can’t find any matching file.
    http:/127.0.0.1/wpmu/blog/2006/11/ -works ok
    http:/127.0.0.1/wpmu/newblog/ -error

    Any advice?

    w

  88. |

    Hi Gary,

    Thanks for letting me know! I’m sorry I wasn’t able to respond to you sooner. I’m glad it’s working.

    What was the key?

    Thanks!
    Tom

  89. |

    Henry,

    I’ve never tried it with the new multi user edition. I imagine you’ll need to edit the htaccess.txt file to work for different blogs. Sorry - I just have no experience with that edition.

    Let me know if you get it working.

    Thanks!
    Tom

  90. |

    Hi Tom

    Have installed your script but my links are just redirecting back to home page what do i do?

    I know i read it somewhere but have tried so many things i am lost?

    Ron

  91. |

    Further to my request I am hosting on a Windows server using IIS 6.0

    My configuration is exactly the same as per your instructions which creates the folder i was after but still redirects to the home page. Im using errorpage.asp and htaccess.php I have also tried htaccess.text with false in the errorpage with the same result.

  92. |

    Hi Ron,

    I took a look at your site, and it looks like you have a problem with the htaccess.php. Try accessing htaccess.php in a browser:

    http://babyshowergifts.babyshowermoments.com/htaccess.php

    The script will redirect to the home page if it can’t find any rules that match. You can change that by changing the variable: Actual404 (at the top of the script).

    Currently your htaccess.php gives an error, so it doesn’t have any rules to work off of. Fix the htaccess.php and the rest will work.

    Best,
    Tom

  93. |

    Hi Tom

    Can you please consider me a dummy, do i change the errorpage.asp file where it has actual=”/” and if so what do I change it to?

    Or are you asking me to add a link into the htaccess.php file

    Ron

  94. |

    Tom,

    I just migrated to IIS yesterday, after two years on Apache. Let me start off by thanking you for the work you’ve done ahead of all of us and then letting us know how you got your permalinks working in IIS.

    My problem at the moment, I believe is because I’ve not been able to set my 404 type to URL explicitly…would that cause me to get an error such as “The request is not supported.”?

    My ISP is using Helm 3.x, so it might be a limitation there and I need to contact them. But if the problem, at this point, is not related to the error handling type…then I should probably cross one bridge at a time.

    Thanks!

  95. |

    David,

    It looks like the error you are getting currently is:

    “The system cannot find the file specified.”

    That would seem to indicate to me that you are specifying a 404 error page that doesn’t exist. You need to set the 404 error to go to: /wordpresss/errorpage.asp

    Be sure to set it to type: URL

    Best,
    Tom

  96. |

    Ron,

    Sorry for the confusion. The problem is with your htaccess.php. No need to change the Actual404 variable. I was just mentioning it so you knew what it did.

    There is something wrong with your htaccess.php. It should spit out something that looks like this: http://www.keyboardface.com/htaccess.txt.

    I would try this:

    1. In errorpage.asp change this line:

    Dynamic = True
    to
    Dynamic = False

    2. Then make sure you have a copy of htaccess.txt uploaded to the server.

    3. Make sure your permalink structure is set up with this pattern:

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

    Hopefully that will get you around whatever error you’re having.

    Best,
    Tom

  97. |

    Tom,

    Turns out my original problem was that ASP was not enabled on my server. After figuring that bonehead move out I’m now in the same situation as Ron I believe. I am using the same permalink structure as you (and as is mentioned in your comment above to Ron). I changed Dynamic to False and updated the htaccess.txt file to contain the same info that you linked too.

    However, I’m still ended up at my actual 404 page when trying to access a permalink.

    I have the htaccess.txt file in both my root directory and my wordpress directory, and that doesn’t seem to make a difference.

    Again, thanks in advance for your help.

  98. |

    Hi Tom,

    My site now just redirects back to the home page all my page links on the right hand side show the pages in a folder but my top bar nav still shows page?=15 so i have now both types of links on my site..

  99. |

    Sorry if this double posts, got an error a bit ago when trying to submit this….

    I think I may be on to something….and this might be a problem with IIS not set up to do the URL type forwarding. I set up a test error page with some PHP….if your ASP file ending up hitting what it deemed a ‘real 404′ then I forwarded to my Php script.

    To do this I modified your ASP slightly so that the Actual404 looked like this….

    Actual404 = “/testerror.php?url=” + Request.ServerVariables(”SCRIPT_NAME”)

    Then, in the PHP I just diplayed whatever the URL parameter is. My ASP/vbscripting is pretty poor, so I may be looking at the wrong variable with my script…but I always end up with “/erropage.asp” as my parameter.

    Is this the result of the way that my error page handling is set up? Or do you think its a different kind of issue.

  100. |

    Hi, I am getting an error when clicking on the post title, “Sorry, no posts matched your criteria.”

    homepage works:
    http://www.wearchildren.com/blog

    category works: http://www.wearchildren.com/blog/category/shirts/

    post doesn’t work:
    http://www.wearchildren.com/blog/shirts/my-first-post/

    My permalink is set to:
    /%category%/%postname%/

    Link to my htaccess.php:
    http://www.wearchildren.com/blog/htaccess.php

    What am I doing wrong?

  101. |

    bueller? bueller?

  102. |

    Worked on ASPNix w/ WordPress v2.0.5 using htaccess.txt - dynamic did not work. I did not have to change anything in the files. Note: Using the same permalink structure as your blog.

  103. |

    Hi Scott,

    Sorry for not getting back to you sooner. The problem has to do with the order of the rules that are being generated. What you want to do is copy the output of your htaccess.php and paste it into a htaccess.txt. Then rearrange the rules so it goes from longest (the most strict) to shortest (the most broad).

    The problem is that there are two rules that will match. The category rule AND the post rule. The program takes the first match and reroutes it. It processes it top to bottom, so you need to put the post rule above the category and you’ll be fine.

    What’s bueller?

    Best,
    Tom

  104. |

    “Bueller” is in reference to the teacher in Ferris Bueller’s Day Off. He repeats “bueller” waiting for the student to reply, but he isn’t there.

    I figured I would get some nepotism and you would answer me faster since I live down the street from you (well, Burbank anyway).

    My php is pretty bad, and my regexp’s even worse, but i will attempt your suggestion anyhow.

  105. |

    Tom,

    First let me say “Cool Tool!”… plus I haven’t had a chance to dig super deep in your blog, but it looks like you’ve got a lot of interesting things to talk about. I predict I will be spending a lot of time reading your blog.

    Anyway, on to the question (thanks in advance for any help you can provide).

    1) I am trying to get your plugin to work with WordpressMU. Have you tried this yet? Any suggestions?

    2) I ran into a total dead end with WordpressMU so I decided to install Wordpress and play around with getting that to work first, figuring that I’d learn the tricks on that system first, and then migrate what I learn to WPMU. I mostly have it working, but I can’t seem to get permalinks to work unless I include the “/index.php/” in the URL structure. As far as I can tell, everything seems to be working fine if I keep “index.php” in there… pages, posts, categories, etc… but when I remove that from the structure, I just get a 500 internal server error.

    By the way, I couldn’t get the htaccess.php to work unless changed:

    require_once(’../permalinks3/wp-blog-header.php’);
    - to -
    require_once(’./wp-blog-header.php’);

    I don’t know if that broke things… I don’t think so, because pages seem to be working so long as I include the “/index.php/” in the path.

    Anyway, sorry for the long post. Would love to get this working on WordpressMU.

    Thanks.

    -Brad

  106. |

    OK. I spoke too soon and your solution only partially worked for me. It would not show user comments on new posts created and categories did not show properly. I am running the newest multi-user edition of WordPress. After searching for hours I found the following php solution that uses 404 redirection and works like a charm.

    http://wordpress.org/support/topic/36214

  107. |

    Well, after playing around with this some more, I think that actually, I don’t have your tool working at all. When I thought I had it working with wordpress, it was actually just working because wordpress’s normal index.php was handling things. Hence why things broke when I tried to make the pretty URLs not have index.php in them. Any tips on how I might be able to debug this? I am tempted to go ahead and build a ASP.Net httpModule or httpHandler, and borrow your clever idea of loading the rules dynamically (since that piece of the system seems to be working).

    At least I am still convinced that I don’t need to switch to apache or use one of the commercial ISAPI plugins. (Those weren’t any easier to get working, by the way.)

  108. |

    I’m trying this idea . . . but every time I click on a link on my blog it just takes me to the homepage of the site my blog is hosted on. I have the blog installed in a subdirectory on my site. Is that why this is happening? For instance, I click on an archive date, and boom! I’m at the homepage of the site (not the blog). I go back to the blog, click on “about” and boom! I’m at the homepage of the site again. Every link takes me back to the homepage. Anyway, obviously I don’t know much but I’m just trying to figure out a way to get the “pretty permalinks” to work on IIS 6. Thanks again.

  109. |

    Can’t get it to work. It always redirects to the index page of my site.

    My blog is in a subdirectory of my main site. Could that be causing the problems?

    Right now, any link I click on in my blog takes me straight to the index page of my main site.

  110. |

    I’ve done all the steps . . .
    Now every link in my blog takes me to my main site index page (my blog is located in a subdirectory of my main website).

    I tried uploading the files to my root of my main site and pointing the 404 page there . . . still the same result.

  111. |

    Eric - I\’m not sure how to solve your problem, but thanks to Jermaine, there might be another good solution using the 404 error page, etc.

    http://www.nathanm.com/wordpress-plugins/

    Scroll down to the \”Wordpress Remove Index.php from Permalinks in IIS Plugin\”

    It sounds like a similar solution, but it\’s PHP based, which fits in with Wordpress a lot better.

    Let me know if it works!

    Tom

  112. |

    blargh. i followed your instructions as stated. (although i have have feeling that i missed something)

    well, the 404 error page works, but i can’t seem to get the blog to get me to the correct entry using the blooming new format. even by posting a new entry…

    i used the custom formatting in the permalinks section of the option tab:
    /index.php/%year%/%monthnum%/%day%/%post_id%/

    it doesn’t like me. nobody likes me. nobody loves me either.

  113. |

    I’m sorry I posted three times above. I didn’t see my post at first so I re-posted, then I didn’t see the post again, so I posted using IE, and then . . . well, anyway, sorry.

    I tried the alternate link you gave me and it WORKS! I’ve been getting so frustrated trying so many different things, but this is really cool. It works! It works! It works! It works! Yippee!

    You are the best. I appreciate your help. I have a serious problem staying up to late and being overly obsessive/compulsive about such things until they’re solved.

    Thank you again and again!

  114. |

    [...] Artigo original (em inglês): Wordpress PermaLinks in IIS without the mod_rewrite. [...]

  115. |

    I have followed the instructions and now when I go to click on a page it pops a download box that says its a binary file and asks what to do with it. I have my blog here

    http://63.134.220.40/blog/. Any ideas of what I did wrong?

    thanks!!
    Shannon

  116. |

    Hi Shannon,

    That’s very strange. It looks like your server isn’t processing any of the ASP code. You should test it by uploading a file named test.asp. The only line you should put in the file is

    response.write("hello")

    Look at it in a browser. If it spews the code back to you, then we’ve spotted the problem.

    Best,
    Tom

  117. |

    Hi Tom,
    Thx alot for you nice solution, I was getting a lot of grey hairs before I found this :-S

    Well finally I still have a Problem, when u visit a page on its permalink, the umlauts are still messed up with ? all over there…
    (link to show: http://blog.cosmicdreams.ch/archives/2007/02/08/permalinks/)

    I did set the encoding in as u mentioned earlier before and I tried latin encoding as well as utf, but without any changes…

    any suggestions?
    bets regards from snowy switzerland
    Jonas Rothfuchs

  118. |

    Thank you for this plugin! I can’t wait to get it working:)

    Am I missing something though? I can’t seem to get this working. Where am I supposed to upload htaccess.txt? Also, will this plugin redirect all old links that included /index.php/ to the new link?

  119. |

    Hi, I had done exactly as told in the readme. I had installed my blog in the root directory. I tried to use a different theme and this is what happens. The homepage works well with the new theme but the category/static pages revert back to the default theme. What did I do wrong?

  120. |

    Ok, found the Clue:

    There are two places where you’ll have to insert Response.Charset():

    so ther Code looks like this (around line 101 of errorpage.asp)

    Else
    If Credits = True Then
    Response.Charset = “ISO-8859-1″ Response.Write(AddCredits(ReturnPage(Path)) Response.End()
    Else
    Response.Charset = “ISO-8859-1″ Response.Write ReturnPage(Path) Response.End()
    End If
    End IF

  121. |

    [...] Nach den anfänglichen Stolpersteinen mit dem Charset für die Permalinks läuft nun alles *uff*. Dank der Lösung von Tom konnte ich die Permalinks auch mit dem IIS benutzen und musste nur noch etwas mit den charsets kämpfen. Dafür kann ich nun etwas ASP [...]

  122. |

    Hi - I cannot seem to get this to work on my hosting farm. Two Windows 2003 IIS 6 load balanced servers.

    Under permalinks in wordpress backend I have this:

    custom structure: /index.php/%year%/%monthnum%/%day%/%postname%/

    category base:
    /archives/category

    I have 404 set to URL, /errorpage.asp

    Errorpage.asp is uploaded, also htaccess.php. Htaccess.php contents are as follows:

    use_verbose_rules = true;
    echo $wp_rewrite->mod_rewrite_rules(); ?>

    With all of this enabled - when you click on the Title of a wordpress entry it just takes you back to the main page of the website. I have spent quite some time messing with this,