May
21
2006

WordPress Permalinks in IIS using Custom 404 Redirect

Update

There is a better way to do this now. Take a look at this post that describes it. This page is kept here for all that have already installed this solution.

Original Solution – Outdated Now

This has been tested with WordPress 1.5 and 2.0

If you have any trouble installing it, you can comment here and I’ll try and help you. Also, if you successfully use this on your server, let me know in the same thread. Thanks!


Requirements

     • IIS

     • WordPress 1.5 or 2.0

     • Ability to change your 404 error page with your web host.

 

Downloads     

 

This solution requires two files: errorpage.asp and htaccess.txt or htaccess.php.

     • Download the Files

 

Installation Instructions

 

1. Log into the admin section of WordPress.

 

2. Click on Options -> Permalinks

 

3. Set your Permalink Structure to “Custom” and enter in a pattern for your permalinks. WordPress has a section that gives all of the permalink structure tags. Mine is currently set to:

    Structure: /archives/%year%/%monthnum%/%day%/%postname%/
    Category Base: /archives/category

4. Click Update Permalink Structure

     

    5. Upload htaccess.php and errorpage.asp into the root directory of your blog.

     

    6. The steps used for this next step will vary depending on your hosting provider. Essentially, what you want to do is set a custom 404 redirect to “/errorpage.asp”. It is important that the type of redirect is set to URL. (There are several options.

     

    You can change this directly from within IIS by selecting Properties -> Custom Errors. Select 404. Edit. Set Message Type to URL (you have the option of File, URL or Default). Set it to /errorpage.asp

     

    7. Your done! Try it out. If it doesn’t work, post a comment on my blog and I’ll attempt to help you out.

     

    The script is now dynamic, meaning it uses htaccess.php to figure out what your permalink rules are. htaccess.php gets the rules directly from WordPress. Previous versions required you to copy/paste the rules from WordPress into htaccess.txt. This feature is still available for those that want to modify the rules from the standard that wordpress puts out.

     

    To do this:

    Get the rules either by accessing htaccess.php in a browser and then copying the source, or by navigating to the permalinks section in WordPress’ admin area.

     

    Paste the rules directly into htaccess.txt.

     

    Change this line in ErrorPage.asp.

    Dynamic = True

    Change it to:

    Dynamic = False

     

Share and Enjoy:
  • del.icio.us
  • digg
  • Furl
  • NewsVine
  • RawSugar
  • Reddit
  • Spurl
  • YahooMyWeb
Written by Tom in: |

36 Comments »

  • [...] 在 Codex çš„ Configuring Permalinks 有æ??到幾個解決方案,以我çœ?å?ƒå„‰ç”¨çš„個性來說, URL Rewrite 還滿å?ˆç”¨çš„。若å?ªéœ€è¦?使用在 wordpress 上,Permalinks for IIS using 404 Redirect 則是é‡?å°? wordpress 的簡易解決方案,以下就ç¨?微介紹一下這個方案。 [...]

    Pingback | July 24, 2006
  • [...] Permalinks on IIS [...]

    Pingback | October 26, 2006
  • [...] It ended up taking me about 4 hours total to find a solution and I don’t want anyone to go through what I just did. While it wasn’t completely smooth KeyboardFace’s page on how to create a function similiar to Mod_Rewrite on an IIS server for WordPress save me. Hallelujah. [...]

    Pingback | November 19, 2006
  • [...] Well, almost success. I still had a problem. I had been using WordPress’s pretty permalinks which do not natively work in IIS, because IIS does not support mod_rewrite. This is a problem for me, after all I had been around for 2 years and my pages are all indexed by a number of search engines. I turned to the web and found an incredibly helpful person in Tom over at KeyboardFace. Tom wrote a slick little ASP script and how-to so that you can get Permalinks for WordPress working in IIS. The process is relatively simple, though I’ve had some issues that I believe are related to not being able to set my custom error page to be of type “URL” instead of “File” or “Default.” You can comment on your IIS WordPress Permalinking experiences here. [...]

    Pingback | December 21, 2006
  • [...] The problem with my attempt at a clever URL rewriter that didn’t rely on a bizzare/slow automatic 404 error handler was great, in theory, until it occurred to me that the ASP.NET 2.0 engine wouldn’t actually ever fire as the result of a request targeted at anything that doesn’t have an ASP.NET file extension, thus my fantasy of targeting virtual URLs and simulating the apache mod_rewrite() command for URL rewriting went up in some. IIS 7.0 looks like it will be able to offer this kind of virtual URL natively to ASP.NET without having to use ISAPI filters (if you use a shared host, even one as good as DiscountASP.NET, they will not let you install one, ever). [...]

    Pingback | July 22, 2007
  • [...] using a custom 404 redirect as explained on the Keyboard face blog. [...]

    Pingback | October 30, 2007
  • [...] De plus, afin de pouvoir profiter des permalink sous toutes ses formes et sans le "/index.php/" nous devions utiliser soit une astuce grâce aux erreurs 404 ou soit (et pour être plus propre) un module d’ URL Rewriting comme celui de Jon Tackabury que j’ utilise pour ce blog et disponible sur IIS.net. A ce sujet, vous retrouverez sur le site de WordPress plus d’ informations sur les permalink et IIS. [...]

    Pingback | February 19, 2008
  • [...] Permalinks on IIS [...]

    Pingback | March 9, 2008
  • Shaklee-NY

    this errorpage.asp will make an error if the post title has a single quote in it. What\’s the fix?

    Comment | July 14, 2008
  • Tom

    All I can think is to remove this line:
    ps = replace(ps, "'", "")

    If that doesn’t fix it, you can replace it with this line:
    ps = replace(ps, "'", "''")
    I couldn’t test it out because we no longer use that solution on this blog. We use the updated version which can be found here:

    http://www.keyboardface.com/archives/2007/09/07/update-for-wordpress-permalinks-on-iis/

    Comment | July 14, 2008
  • Shaklee-NY

    This works well but causes a problem with Frontpage. On IIS, if you install Frontpage then permalinks will crash. HELP?

    Comment | July 21, 2008
  • Prashant

    Hi,

    I am having a domain registered on shared web hosting IIS7 I want to run wordpress paramlink but its not running i have tried your trick but its also not working its (wordpress blog) always displaying that you have got wrong url.

    And also i want to run wordpress on subdomain is there any problem with that???

    Thanks,
    Prashant

    Comment | July 30, 2008
  • Prashant

    and also tell me taht your solution will work with wordpress 2.6

    Comment | July 30, 2008
  • Tom

    Prashant, IIS7 has a better and different work-around. It involves editing the web.config file.

    Here’s a link to a page that goes over it:

    http://learn.iis.net/page.aspx/466/enabling-pretty-permalinks-in-wordpress/

    Best,
    Tom

    Comment | July 30, 2008
  • still-struggling

    I installed wordpress on IIS and am only having one problem after the next. As described above, permalinks corrupts frontpage. So I removed frontpage. Now, my wordpress does not have a .htaccess file at all! There is a htaccess.php, but none that starts with a .

    Also, I am running a classic asp website, and on the right column, I’m including a file that parses a feed from the blog. It says ‘recent posts to my blog’. It runs perfectly fine, except after includig that, within minutes the site hangs. The site will not work if it is pulling my blog feed file. So including the xml [parser crashes my site. It is using too much resources to parse. I don’t understand this problem.

    Either way I love wordpress and I’m willing to persevere until I get it right. So A – gotta make permalinks work with frontpage. B – gotta make those recent posts show up nicely without overtaxing the server. And C – I’m not sure why but I downloaded the errorpage.asp from here http://www.keyboardface.com/iis-permalinks/ and it works nice, but only if the blog is in the /blog directory, not if your blog is the root of the site.

    Comment | August 25, 2008
  • |

    [...] to http://www.keyboardface.com for providing the answer.Click here to get the original [...]

    Pingback | August 26, 2008
  • [...] what is listed in Google. Turns out this problem had been resolved by the community at large and with a little hack we had all of our Google ranked pages back and working [...]

    Pingback | August 31, 2008
  • Hi, I cannot implement the pretty perma link structure in this wp blog. Can u please help me in this regard. http://blog.cfstyle.com

    Comment | August 31, 2008
  • Hi,
    It worked fine for me with the given structure and category base. But i want to use this for the permalink structure as
    http://www.localsadda.com/%postname%/. How can i implement this. What are modifications need to be done?
    Can you help me out?

    Comment | September 6, 2008
  • [...] http://www.keyboardface.com/IIS-Permalinks/ – 404 page solution [...]

    Pingback | September 18, 2008
  • [...] http://www.keyboardface.com/IIS-Permalinks/ [...]

    Pingback | October 18, 2008
  • [...] http://www.keyboardface.com/IIS-Permalinks/ [...]

    Pingback | October 18, 2008
  • Tomas

    Actually in wp new beta this method works again!

    Comment | November 9, 2008
  • Arren

    Absolutely brilliant, thank you thank you thank you

    Comment | January 2, 2009
  • [...] Version (see here for referred article) – Download files here – Upload htaccess.php and errorpage.asp into the root [...]

    Pingback | January 12, 2009
  • E.Karnika Yashwant

    great..thanks and thanks again

    Comment | February 27, 2009
  • [...] Codex has a very useful page about working with permalinks, there’s one solution that uses 404 error pages, however when you look at what it does it’s very slow and again very nasty. The 404 error solution [...]

    Pingback | March 17, 2009
  • B3

    almost worked!
    the only part that didnt work was the comment box is not visible, and always says you must login, even when you are. as soon as i removed the 2 files the comment box came back and said i was logged in

    Comment | March 17, 2009
  • [...] Codex has a very useful page about working with permalinks, there’s one solution that uses 404 error pages, however when you look at what it does it’s very slow and again very nasty. The 404 error [...]

    Pingback | April 3, 2009
  • [...] Using Permalinks section on the WordPress page has a lot of info on this and it links to one solution that uses custom 404 pages to make this work but unfortunately I don’t think it’s a very good solution at all. What it [...]

    Pingback | June 12, 2009
  • [...] Using Permalinks section on the WordPress page has a lot of info on this and it links to one solution that uses custom 404 pages to make this work but unfortunately I don’t think it’s a very good solution at all. What it [...]

    Pingback | July 29, 2009
  • [...] Using Permalinks section on the WordPress page has a lot of info on this and it links to one solution that uses custom 404 pages to make this work but unfortunately I don’t think it’s a very good solution at all. [...]

    Pingback | September 15, 2009
  • [...] This solution supercedes the ASP solution. [...]

    Pingback | September 23, 2009
  • [...] http://www.keyboardface.com/IIS-Permalinks/ [...]

    Pingback | October 15, 2009
  • wordpress pretty permalinks iis

    i was struggling with this problem from few days, and after search so much stuff i got solution and now i have pretty permalinks
    in my self hosted (IIS7+ windows Server)blog.
    (Prerequisites: PHP5.0+ Version and FAST CGI SCRIPT – Don’t use ISAPI Filter)

    I have made one web.config you need to put that file in your root directory and done.
    http://www.geekblogger.org/2010/03/how-to-set-pretty-permalinks-in.html

    Comment | March 19, 2010
  • [...] then came across Tom Bristol’s great little ASP script to parse the .htaccess file to ensure that I had nice clean SEO links instead of [...]

    Pingback | May 18, 2011

RSS feed for comments on this post. TrackBack URL

Leave a comment


8 − seven =

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes