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:
Scott Elkin says
bueller? bueller?
Jermaine says
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.
Tom says
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
Scott Elkin says
“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.
Brad says
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
Jermaine says
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
Brad says
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.)
Eric says
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.
Eric says
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.
eric says
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.
Tom says
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
tery says
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.
Eric says
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!
Shannon says
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
Tom says
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
Jonas says
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
Alex says
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?
wwcnet says
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?
Jonas says
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
Ron says
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, and it is really bugging me. I would love to get it to work.
I have the changes currently still implemented on the live website @ sysadm1n.com so please do check it out to see the behavior.
Regards,
Ron
Ron says
In response to the above, the full contents of my htaccess.php file were not displayed in the comment for some reason.
To see the entire contents check: http://www.sysadm1n.com/htaccess.txt
Regards,
Ron
Lovely_angel_for_you says
Hi Tom,
Wonderful small application. I am pretty sure it must have helped lots of people in getting their blogs up and running with permalinks. However, when I used it, it only does one thing. Bring me back to my homepage.
Came to your support link. And started from downwards up, as thats where you find latest issues with the latest update. And just right there was a link that you suggested.
http://www.nathanm.com/wordpress-plugins/
Wow!!! Does that work? No it doesnt work, it makes my blog look pretty, pretty with permalinks.
Thanks a lot.
Regards
Lovely
Content Goldmine says
Thanks for the wonderful solution!
I finally got it to work on my IIS server. It didn’t work the first time. I think my server didn’t like Dynamic=True setting.
When I set Dynamic=False, it works! I think I can live with the static method and configure htaccess.txt manually.
I managed to make the URL looks just like how it appear on my other blog hosted in a Linux server i.e. /%year%/%monthnum%/%postname%/ and /category. Now I can move my blog from IIS to Linux and vice versa!
For those who are interested, you can see my modification at
http://www.content-goldmine.com/htaccess.txt
nat3 says
Hi, I use your script and it’ fix many problem for my site about path but one problem that your script has is encoding. I use binary convert function from site : http://p2p.wrox.com/topic.asp?whichpage=1&TOPIC_ID=7695𘎃 to fix it and now it’s ok.
I made some change in your script by add this function.
Function bts(data)
‘Converts binary data to string
sOut = “”
For i = 0 to UBound(data)
sOut = sOut & chrw(ascw(chr(ascb(midb(data,i+1,1)))))
Next
bts=sOut
End Function
and change
ReturnPage = xml.responseText
to
ReturnPage = bts(xml.responseBody)
and at last thank for your solution.
Tom says
Hi Nat,
Wow – Thanks – That’s exactly what several people have been trying to fix. I’ll be sure to add that in the next release of the script.
Best,
Tom
Gert Leroy says
hello Tom,
thanks for this post, but unfortunately it doesn’t work for me..
i have set permalinks custom structure to:
/%year%/%monthnum%/%day%/%postname%/
i have configured the 404 to /errorpage.asp and downloaded the archives fro this post.
whenever i click on whatever link in my blog, it get’s always redirected to the homepage.
I really don’t know what to do. Can you please help me out?
One thin that caught my eye is the htaccess.php. The code is:
use_verbose_rules = true;
echo $wp_rewrite->mod_rewrite_rules(); ?>
where does the path “../permalinks3/wp-blog-header.php” come from?? i don’t have this directory.. anyway i don’t know if that’s the problem. I’ve been braeking my head over it almost 2 days now. Rescue me.
Gert Leroy says
Sorry, the code came out wrong in this text-editor.
the line i’m talking about is:
require_once(‘../permalinks3/wp-blog-header.php’);
My blog is http://www.sao-miguel-do-gostoso.com/
Tom says
Hi Gert,
Thanks – I think you found the problem. htaccess.php should read
require_once("./wp-blog-header.php");
It shouldn’t have the permalinks3 in it. That was added by my code editor and shouldn’t have. I have fixed it in the zipped file that gets downloaded, but you may want to edit it by hand and try it out.
Thanks,
Tom
Gert Leroy says
Hi Tom,
thanks for the fast reply. I have changed the path but now it seems that the browser gets stuck. it keeps on searching for something. Check it out on http://www.sao-miguel-do-gostoso.com/
thanks
Tom says
Hi Gert,
I checked your site out and it appears that if you try and access htaccess.php by itself, the server hangs. I bet that’s where the error is coming from. Make sure you can access htaccess.php by itself at http://www.sao-miguel-do-gostoso.com/htaccess.php and it should then work.
Best,
Tom
Gert Leroy says
ok.. easier said than done ;o)
the server hangs indeed on htaccess.php
what can be the reason? how can i make it work?
(i’m not really a programmer you know, i’m just a guy who likes windsurfing..)
Darren Atkinson says
Hi
Thanks for the contribution, it looks like just what I’m after.
Problem’s Im having so far are:
– If I change structure to something like:
/archives/%year%/%monthnum%/%postname%/
All links redirect to the homepage, also even with the structure you suggest in the instructions it works for new posts, but old posts get a Not Found message.
Any ideas?
Thanks
Tom says
Darren,
If all links redirect to the homepage, that means that none of the rules matched and therefor it is redirecting you to the homepage.
If it is giving you a not found message that means that it is confused by the rules. It may be that it is using the “year” to look up the “post name” or something like that.
I hope that makes sense.
Are you using dynamic or static rules?
Best,
Tom
Darren says
Tom,
Thanks for the reply.
I have tried using both ways, I will try and have a play around with the htaccess.txt file, although I’m probably shooting in the dark.
I’d really love to be able to get your script working properly before I launch my blog.
Cheers
Darren
Trevor says
Doesn’t work for me. I get a VBScrpt error:
Microsoft VBScript runtime error ‘800a0005’
Invalid procedure call or argument: ‘Right’
/errorpage.asp, line 25
Not sure how to troubleshoot that.
Thanks,
Trevor
Tom says
I believe that means that you have the 404 error page set with type “file” not type “url”
Best,
Tom
Milan says
Hello Tom,
I tried your solution,
but for some reason it redirects me always to the root url.
My blog is on http://triporiginator.com/travelarticles/ – doesn’t mater what I click, it redirects me to http://triporiginator.com
Can you please help!
Thanks
Milan
Tom says
Hi Milan,
The problem you are talking about actually is an error in the script itself. It’s been corrected.
Redownload the script and upload errorpage.asp to the server and it should work now.
Best,
Tom
Darren says
Hi Tom,
Still no joy getting it working, same problem as Milan. Tried redownloading the script but it still aint working, just redirects to site root.
If I click on a category, the url changes correctly but my homepage is loaded with no stylesheet or images. All other links in the blog simply redirect to homepage.
I have tried both dynamic true and false with the exact same results.
Any further thoughts?
Darren
Owen says
Great solution, thanks for the effort.
One problem I have is that the server seems to use a seperate session for the page it displays. So, for example, I appear logged in on the home page, but I don’t appear logged in on any of the post pages (that are going through the custom 404). Anyone has any idea how to resolve this?
Owen
Tom says
Hi Owen,
That’s a great point. I hadn’t thought of that. I believe the 2nd session is due to the fact that ASP pretending to be another user looking at the site and then displaying what it sees to the actual user.
I haven’t run into a problem with that because I don’t require people to be logged in to leave a comment.
One way to work around it is to have the comment link go to the actual page: index.php?p=… On the actual page they will be logged in.
I haven’t tried logging in on a 404 error page either, though. It could be that if you log in through a 404 error page, you’ll be logged in through the rest of them.
You’ll have to try it.
Best,
Tom
Brian says
I’m getting the same error as Trevor…
Microsoft VBScript runtime error ‘800a0005’
Invalid procedure call or argument: ‘Right’
/errorpage.asp, line 25
Not really sure what to do about this. Any ideas?
Tom says
Hi Brian,
The reason you are getting that error is the same reason Trevor was. The solution would be the same as well.
I believe that means that you have the 404 error page set with type “file�? not type “url�?.
Best,
Tom
Paul says
Couple problems:
It does not like logged on people. For example, I log on, I click on a link that uses your code, and suddenly I am no longer logged into that page. I click on Logon, and suddenly I am logged in again.
For some unknown reason it does not play nice with http://wordpress.org/extend/plugins/cforms/ Now that may just be the way it is setup.
I do like what you have done though. Great work. Hint for others: If your server is behind a firewall with an internal IP only with the firewall port forwarding traffic, add the host info to that server;s hosts file, eg
my external ip for http://www.whome.com is 99.123.11.8
my internal ip is 192.168.1.5
The firewall take all traffic aimed at 99.123.11.8:80 and forwards it to 192.168.1.5
So my hosts file will look like:
192.168.1.5 http://www.whome.com
John Greathouse says
I tried your solution and it doesn’t seem to work for me. When I try to implement on my wp 2.2 blog at http://blog.greathouse.net the site never appears / responds. If I reset the permalinks setting in wp-admin back to it’s orgional default setting and the site starts responding / appearing again. http://blog.greathouse.net is a virtual directory setup under the main web site. I tried setting the Dynamic = False and that did not help.
I am trying to use the same permalink structure you specified in your read me….
Structure: /archives/%year%/%monthnum%/%day%/%postname%/
Category Base: /archives/category
I preformed no other modifications.
Thanks
John
Larry says
I’ve been working this problem for a few days with no luck. I’m trying to use Copyblogger 1.0 by Chris Pearson and he has even looked at it and doesn’t appear to be able to help. I’ve tried using your solution “Wordpress Permalinks in IIS using Custom 404 Redirect” but all that happens is nothing my browser just sits there trying to load the page and never does. I’m starting to think that it is not possible to make Permalinks work on a Windows 2003 server. I’m hosting WordPress at Blazer Network http://www.blazernetwork.com/ using a Windows 2003 server. I’m using the latest version of WordPress version 2.2.1. I’m using Blogger right now to host my blog but I would like to transition to WordPress but I would like permalinks to work before I make the switch. I have a test version of WordPress setup at http://flyballblog.i-flyball.com/ . Can anyone make any suggestions that I might be able to try? Thanks, Larry
Ishan says
Ok Tom, This is not working.
I uploaded the .htaccess file and the other 2 as per the readme. The directory structure is:
Index.php – Site Root
.htacess – SiteRoot
all other WP files
in a folder called /blog
The Blog works great when I turn of permalinks.
I also added the Error 404 setting on my control panel…
Please take a look at it.
thanks
Ishan