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:
Antoine Khater says
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
Antoine Khater says
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
Antoine Khater says
I am really sorry for the multiple posts š I kept on refreshig the page but they didn’t show up
Jennifer says
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. =)
Paul Cardwell says
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!
Zach S. says
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
Tom says
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?
Zach S. says
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?
Tom says
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?
Vialuna says
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.
Tom says
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.
Vialuna says
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.
Tom says
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”.
jatubio says
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!!
Tom says
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
Living says
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!
Tom says
Thanks! I’ve added that line to the main download.
Domokos says
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
Tom says
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
Chance says
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)
Tom says
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
chance says
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
Chance says
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
chance says
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!
Tom says
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
Jared says
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.
Gary says
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
Chance says
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!
chance says
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!
Tom says
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
Gary says
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
Tom says
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
chance says
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
chance says
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!
Gary says
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
Gary says
Hi Tom,
Finally got it all working!
Regards
Gary
Henry says
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
Tom says
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
Tom says
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
Ron says
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
Ron says
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.
Tom says
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
Ron says
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
David McNelis says
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!
Tom says
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
Tom says
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
David McNelis says
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.
Ron says
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..
David McNelis says
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….
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.
Scott Elkin says
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?