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. Antoine Khater says

    August 17, 2006 at 5:48 am

    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

  2. Antoine Khater says

    August 17, 2006 at 6:18 am

    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

  3. Antoine Khater says

    August 17, 2006 at 10:48 am

    I am really sorry for the multiple posts šŸ™ I kept on refreshig the page but they didn’t show up

  4. Jennifer says

    August 18, 2006 at 2:14 am

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

  5. Paul Cardwell says

    August 20, 2006 at 7:22 am

    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!

  6. Zach S. says

    September 4, 2006 at 12:54 pm

    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

  7. Tom says

    September 4, 2006 at 1:22 pm

    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?

  8. Zach S. says

    September 4, 2006 at 6:02 pm

    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?

  9. Tom says

    September 6, 2006 at 11:06 pm

    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?

  10. Vialuna says

    September 7, 2006 at 9:07 am

    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.

  11. Tom says

    September 7, 2006 at 10:55 am

    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.

  12. Vialuna says

    September 8, 2006 at 2:57 am

    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.

  13. Tom says

    September 8, 2006 at 10:38 pm

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

  14. jatubio says

    October 7, 2006 at 7:53 pm

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

  15. Tom says

    October 9, 2006 at 11:05 pm

    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

  16. Living says

    October 12, 2006 at 1:48 pm

    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!

  17. Tom says

    October 12, 2006 at 4:44 pm

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

  18. Domokos says

    October 17, 2006 at 4:13 am

    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

  19. Tom says

    October 17, 2006 at 10:36 am

    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

  20. Chance says

    October 26, 2006 at 7:59 pm

    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)

  21. Tom says

    October 26, 2006 at 11:37 pm

    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

  22. chance says

    October 27, 2006 at 2:20 am

    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

  23. Chance says

    October 27, 2006 at 6:01 am

    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

  24. chance says

    October 27, 2006 at 6:29 am

    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!

  25. Tom says

    October 27, 2006 at 10:57 am

    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

  26. Jared says

    October 27, 2006 at 11:14 am

    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.

  27. Gary says

    October 27, 2006 at 4:01 pm

    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

  28. Chance says

    October 27, 2006 at 5:23 pm

    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!

  29. chance says

    November 1, 2006 at 6:25 pm

    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!

  30. Tom says

    November 2, 2006 at 11:08 am

    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

  31. Gary says

    November 2, 2006 at 1:54 pm

    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

  32. Tom says

    November 2, 2006 at 5:00 pm

    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

  33. chance says

    November 2, 2006 at 5:43 pm

    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

  34. chance says

    November 11, 2006 at 9:50 am

    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!

  35. Gary says

    November 12, 2006 at 5:23 am

    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

  36. Gary says

    November 13, 2006 at 11:20 pm

    Hi Tom,

    Finally got it all working!

    Regards

    Gary

  37. Henry says

    November 14, 2006 at 12:41 am

    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

  38. Tom says

    November 14, 2006 at 4:27 pm

    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

  39. Tom says

    November 14, 2006 at 4:29 pm

    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

  40. Ron says

    December 13, 2006 at 2:30 pm

    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

  41. Ron says

    December 13, 2006 at 3:54 pm

    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.

  42. Tom says

    December 13, 2006 at 5:45 pm

    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

  43. Ron says

    December 13, 2006 at 9:49 pm

    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

  44. David McNelis says

    December 15, 2006 at 9:51 am

    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!

  45. Tom says

    December 15, 2006 at 11:36 am

    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

  46. Tom says

    December 15, 2006 at 11:45 am

    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

  47. David McNelis says

    December 15, 2006 at 1:26 pm

    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.

  48. Ron says

    December 15, 2006 at 4:53 pm

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

  49. David McNelis says

    December 18, 2006 at 11:33 am

    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.

  50. Scott Elkin says

    December 29, 2006 at 10:42 pm

    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?

« Older Comments
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