

UPDATE 16.09.2009: I don’t update this script anymore, it might not work on newer versions of Wordpress. An updated, more robust solution can be found at http://www.ikailo.com/94/url-modrewrite-workaround-iis-60/, go there if the solution below causes problems for your site.
I’ve been searching the web a bit for a way to make pretty permalinks work correctly on this site. The site is hosted on IIS so using mod_rewrite won’t work, and it’s on a shared server so the option of installing a mod_rewrite alternative for IIS won’t work either. I could get away with having almost pretty urls, with a index.php in them, like this: http://tech.einaregilsson.com/index.php/2007/07/30/pretty-wordpress-permalinks-on-iis/ but I didn’t like it.
The 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 does is parse the url from the 404 string, then re-implement all the rewrite url matching itself, make its own http request to the correct url, then write the data from that request into the response. It’s a good effort but it’s duplicating functionality already in Wordpress and making a new http request for every page hit which I don’t like. After searching around some more I found another 404 page solution that is very simple and elegant. All you have to do is create a 404 page and put the following 4 lines in it:
<?php
$qs = $_SERVER['QUERY_STRING'];
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['REQUEST_URI'] = substr($qs, $pos);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>
All this does is fix the REQUEST_URI and PATH_INFO variables and then include index.php, so Wordpress will do the rest. It’s simple, it doesn’t duplicate functionality already in Wordpress and it doesn’t have the overhead of another http request for every page hit. The installation steps are:
/%year%/%monthnum%/%day%/%postname%/






Hi Einar,
I found a weird stuff… I got my home page back when i give /blogs/%category%/%postname%/.
But i am getting /blogs with all my links. example: http://blogs.neuronring.com/blogs/science/sciencefictions/life-after-death/
Do u know one thing? it is working not because of /blogs(because my blogs are already in a subdomain and wp files are directly into it).
whatever i give infront of /%category%/%postname%/ it is working. (i m getting my home page)
ex: /blahblah/%category%/%postname%/ (blog home page with all posts displayed)
but not without anything in prefix of /%category%/%postname%/
ANY IDEAS GUYZ ???
Regards,
R.Gopinath
http://blogs.neuronring.com
[...] Permalinks was way back in the first module, and I just not got it all straightened out. My blog is on a windows host and that is what created the problem. If you have a windows host and are having problems customizing your permalinks, check out this solution regarding permalinks using custom 404 redirects. It’s the one that helped me and I hope it helps you: http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
This worked for me for a long time until recently. I don’t know if it’s because of a change in the newer versions of wordpress or because of something my host might have changed. Can someone confirm that this still works with WP 2.8.3?
Yes Michael. I am using wp 2.8.3. Custom 404 redirect is working fine for me.
Thanks,
R.Gopinath
http://blogs.neuronring.com
This method is useless…..
Google found the custom 404 error page as illegal.
i am getting this message
“We’ve detected that your 404 (file not found) error page returns a status of 200 (Success) in the header”
Is there any way to do this without sending 404 Not Found for every WordPress page, feed, etc.?
Here’s a fix for v2.8.4:
Add this line:
$_SERVER['HTTP_X_ORIGINAL_URL'] = $_SERVER['REQUEST_URI'];
right before this line: include(’index.php’);
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
I love your site.
Love design!!! I just came across your blog and wanted to say that Ive really enjoyed browsing your blog posts. Sign: ndsam
Sign: umsun Hello!!! rcuwwymhyw and 4515ssgfhphzye and 4681Thanks. We look forward to hearing from you again and for your opinions on the world of work.
hi thanks for the code, it worked like a charm!
i want to know if its possible to write a custom 404 page which can handle bbpress permalinks as well as wordpress permalinks in the same 404 file. iam running the forum at mywebsite/forum
thanks
[...] found that the existing solution for using pretty permalinks with Wordpress and IIS is lightweight, but not very [...]
[...] 原文:http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
[...] IIS and GoDaddy Subdomains don’t see eye-to-eye is somewhat an understatement. There is an excellent solution that works for most cases, but it assumes you can set the 404 page for each of your domains – another flaw in the [...]
Hello everyone,
I am running a blog with Wordpress 2.8.4 and messed up with the .htaccess file within the wp-admin folder. Since then, I am getting a “Error 404 – Not found” white page whenever I click on a permaling on the home page of my blog, or when I try to log in, from the admin window.
I cannot figure what is the exact code to place in the .htaccess file in the wp-admin folder.
FYI, here is the content of the .htaccess in my root folder :
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
The first two lines are because I am hosted by 1and1.fr
Any idea about the .htaccess file withing wp-admin ?
Any help would be greatly appreciated !
Thanks, and all the best from Paris;
Benjamin
[...] 不管怎 , 成功去掉了index.php!最后感谢英文作者einar 提供的天才设置方法! [...]
[...] 6 以上版本, 使用 404处理技术 或者 Mod-Rewrite Pro [...]
[...] Using IIS 404 redirect hack provides Pretty Permalinks but user do include index.php in Pretty Permalinks. a 404 handler [...]
Impressive Article , I considered it wonderful
I look forward to more great postings like this one. Do you have a RSS I can subscribe to for updates?
[...] Microsoft IIS 6+ using a 404 handler or Mod-Rewrite [...]
I’m not a php programmer but shouldn’t it be pos+3 not pos+4?
Can you please explain what all of the code does? Thanks!
[...] a shared server so the option of installing a mod_rewrite alternative for IIS won’t work either. Go to Source Related Posts:Most Popular PC World Stories of 2009 (PC World)Never enough time to tinker at [...]
[...] a shared server so the option of installing a mod_rewrite alternative for IIS won’t work either. Go to Source Related Posts:Pretty Wordpress Permalinks on IIS " tech.einaregilsson.comMost Popular PC World [...]
[...] a shared server so the option of installing a mod_rewrite alternative for IIS won’t work either. Go to Source Related Posts:Pretty Wordpress Permalinks on IIS " tech.einaregilsson.comPretty Wordpress [...]
Спорно, но как вариант
Thanks!
But the code displayed dont’t work for me, the downloaded one works fine.
Generally I do not post on blogs, but I would like to say that this post really forced me to do so, Excellent post!
I’m Out!
It works well. but i have a problem with the feed page (feed/), the direct page (?feed=rss2) works.
It seems that the 404 handler write something inside the code of the feed page.
You can see it here: http://www.pattume.it/feed
I have solved with:
if(!strpos($qs, “/feed/”))
set_error_handler(”customError”);
[...] upgrade to Win 2008 & IIS 7 eventually, but didn’t want to do that just for this, so found a moderately ugly hack that puts some code in a 404 (page missing) [...]
[...] Microsoft IIS 6+ using a 404 handler or Mod-Rewrite [...]
Good! it works
very good works for wp
[...] work either. I could get away with having almost pretty urls, with a index.php in them, like this: http://tech.einaregilsson.com/index.php/2007/07/30/pretty-wordpress-permalinks-on-iis/ but I didn’t like [...]
Purchasing memory is such a big hassle… You have to Google prices, sort through which ones are genuine, go out to a bunch of shops,compare prices, finally buy your memory, and then hope that the price doesn’t fall in the next 2 weeks or so.I’ve been screwed over by some ridiculous price drops in the past… especially this one time when I bought a Micro SD for my R4 gaming flash card at what I mistakenly assumed was a steal, only to later see that it fell by $5 in a week’s time.(Posted using NewPost for R4i Nintendo DS.)
[...] Originally posting Published: February 22, 2010 Filed Under: Web design Tags: IIS : Permalinks : wordpress Leave a Comment Name: Required [...]
[...] 另一个非常简单的自定义404重定向解决方案: http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
Nice stuff! Works great!
Nice stuff! Works great!
**edit to fix site link…. =P