A place for my programming projects and the occasional blog about technology related matters.
Pretty Wordpress Permalinks on IIS
Author einar
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'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_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:
- Create the file wp-404-handler.php in your base Wordpress folder. (you can also download it here).
- Set your sites 404 page to point to the wp-404-handler.php url. Most control panels at web hosts allow you to do this. If you’ve got the option to select between FILE and URL then choose URL.
- Go to Options -> Permalinks in your Wordpress admin page, and choose an appropriate structure for your links. I chose Custom with this pattern:
/%year%/%monthnum%/%day%/%postname%/ - Enjoy!
Reader's Comments
Comment
Options
-
July 30, 2007 -
code, meta, wordpress -
136 comments
-
Comments RSS -
Del.ico.us
-
Digg!
Categories
- ASP.NET (1)
- C# (4)
- code (10)
- extensions (2)
- haloscan (1)
- javascript (2)
- meta (2)
- mozilla (2)
- msn (1)
- plugins (2)
- python (3)
- tips & tricks (3)
- utilities (1)
- Visual Studio (1)
- wordpress (5)
- zenphoto (2)
This is nice. I had been using the previous IIS solution before but will use this one for now. I am trying to preserve normal 404 HTTP status codes for SEO if possible. This solution sends the 404 status code but shows nothing on the page. It would be good to be able to display a 404 page if the requested page is not found. I am trying to work on a simple solution for IIS in ASP that would use Server.Transfer as opposed to Response.Redirect. Server.Transfer would preserve the URI and would also not require an additional HTTP request.
Great work!
I knew there should be a way to do it using PHP. I came up with the ASP solution a couple years ago and it worked, so I stopped looking.
Thanks - I’ll redirect people to this solution when I get a chance to write about it.
Best,
Tom
keyboardface.com
@Trevor: I had a bit of trouble with my 404 pages at first too. Then I figured out that I didn’t have a 404.php page in my current template. After I added that it seemed to work fine. Check something like http://tech.einaregilsson.com/2005/05/30/foo to see the 404 page. Before I sometimes just got my front page for a 404 and sometimes got a totally blank page. Regarding Server.Transfer, that would preserve the URI but you wouldn’t get any benefit over using this solution, both only have the single http request.
@Tom: Yeah, I used your solution for some time on my other site and it worked fine
But I didn’t actually come up with this solution myself, I found it on a Wordpress message board that I linked to in the blog post.
I modified this a bit to use on my local test copy of Wordpress (since the localhost $_SERVER['QUERY_STRING'] does not include ‘:80′). On there it goes to 404.php okay when a page is not found, but for some reason on my production site (trevorpowell.com) it just brings up a blank page. If you have any insight, it would be great to hear.
@Trevor: Ah, I didn’t realize about the localhost. Maybe I should fix it to consider that case. About the 404, only thing I can think of is to try to turn some more error reporting on. You could try changing this line in wp-settings.php:
error_reporting(E_ALL ^ E_NOTICE);
to error_reporting(E_ALL);
There is also an option to call $wpdb->show_errors(); but I think that’s only for database errors. One other thing I can think of, have you modified a lot of your Wordpress code files? I had once added a few echo statements in some places I was trying to understand how worked, and then I just got blank pages for all the pages on my site with no errors or anything.
One other thing, do you use the modified version of wp-404-handler.php on your production site or the original version?
That’s about all I can think of, I’m not really a php expert, sorry
This page:
http://www.nothing2hide.net/wp-plugins/wordpress-global-translator-plugin/#comment-4651
recommends going to Options - Reading and turning off gzip compression for another blank page problem, maybe that might work? (Don’t know why it would, but it’s worth a try :)).
Here’s my modified script that will work without the port in the query string:
I have tried using both this and the original on my production site. If I set a different HTTP status header in my 404.php file (200 or even 410), it works. It is only when the HTTP status header is 404 that it returns a blank page. I suspect it must be some PHP ini setting.
The comment form must have eaten your script :). But your 404.php, what happens if you don’t mess with the status header at all in it? In my 404.php I don’t do anything, I just have a normal page with a heading saying ‘File not found’, Wordpress seems to take care of sending the 404 header just fine.
Hi, My host server doesnt allow me to set option to URL. I can only use as File and is not working. Any idea to work around? Thanks
myo
I’m afraid there’s not much you can do with file 404’s. Not that I know of at least. You could try looking into Server Side Includes (http://support.microsoft.com/kb/203064) but I doubt it will work. Sorry
[...] Tip of the hat to: Einar Egilsson [...]
[...] Another very simple custom 404 redirect solution can be found at: http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
I’ve just spent 36 hours reading every page on permalinks in the wordpress codex, downloading ‘deans migration plugin, objection rediretion, search-permalink plugin, permalink redirect plugin, and i tried the keyboardface custom 404 page’ NONE OF THEM WORKED! So if like me you are using wordpress 2.2 on a windows server (not ajax) don’t have a .htaccess file and don’t know what a chmod or modrewrite is try this method cos it genuinely works and the other methods will just leave you with broken links or a broken site.
Thanks again EINAR for finding this fix and spreading the knowledge please try and put this round the net some more so no-one else loses an entire weekend of their summer!
einar I need help!
This solution worked fine for my old posts that were in the wordpress default permalink style (p=123) it relinked all my old posts but now all my new posts show up like this:
http://www.pitchslap.co.uk/wp-404-handler.php?404;http://www.pitchslap.co.uk:80/robinson-is-an-all-right-keeper/
and are being redirected when they shouldn’t need to be
I am trying to get them like this http://www.pitchslap.co.uk/robinson-is-an-all-right-keeper/
Any idea what i’m doing wrong? and i was so sure i’d solved the problem…. just when you think your out, they pull you back in!
Hmm, that’s strange. I tried viewing one of your blog posts with the Live Http Headers extension and it seems that your site is sending a 302 Object moved response when you try to get to the post. I.e. instead of just executing wp-404-handler.php behind the curtains and returning the results it’s explicitly telling your web browser ‘No, go to that address instead’.
How did you set up your 404 page? Do you run your own server or is it through some hosting control panel? Can you choose between something like URL, FILE or REDIRECT? If so you should use URL, not REDIRECT.
If it was working before then I’m not sure what’s going on. I notice that you don’t have any year, month, date information in your urls. That shouldn’t matter, but still, try using the same pattern as suggested in my blog post and see if that has any effect.
Let me know what happens.
I’ve just put up a new post with the year/month/day/postname permalinks but its still doing the same thing.
I set up the 404 by downloading the file from here, then uploaded via filezilla. I have hosting through a control panel at my hosts and there i went to “custom error pages” selected the option to have “a different page for each error” and for “404:not found” i specified the url as “www.pitchslap.co.uk/wp-404-handler.php”. There is no option to change between urls,files and redirect you can just type a file into the box after “www.pitchslap.co.uk/”
Do you think this could be happening because i installed other permalink redirection pluggins before trying this, or because i’ve changed my theme to “greenlove” by bob and edited the header etc?
Thanks for replying so fast einar, any help you can give me would be fantastic as i am really struggling!
I think it’s happening because your hosting company has the 404 pages set up as redirects. If you have no option to select anything other than what you have now then I’m afraid that you’ll have to have the /index.php/blog-post-name/ style of posts.
Sorry
i’ve just had a look in my hosting control panel and every single error page “400″ “401″ “403″ “500″ is sending me to my homepage even though i haven’t specified a file for the error page. “404″ is sending to http://www.myblog.co.uk/wp-404-handler but its still just displaying my homepage.
The index.php/blog-postname would be okay to use but i just tried it on my second to last post but it has already reverted to year/month/day/postname for all my entries even the ones from june that were wordpress default (p=123).
Do you think it has anything to do with this pluggin i installed:
function aja_spredir() {
if (is_search() && $_GET['s']) {
if (!empty($_GET['paged'])) {
$aja_uri = get_bloginfo(’url’) .’/search/’. urlencode(get_query_var(’s’)) .’/page/’. get_query_var(’paged’) .’/';
} else {
$aja_uri = get_bloginfo(’url’) .’/search/’. urlencode(get_query_var(’s’)) .’/';
}
wp_redirect($aja_uri);
}
}
add_action(’template_redirect’, ‘aja_spredir’);
Sorry for taking up so much of your time, i am looking all over the net for a solution at the moment but yours is the closest i’ve come to success,
thanks again even if you can’t help
I don’t think the plugin has any effect. But you could try uninstalling it. I still think the problem lies with your hosting company.
I have no idea now?! Seriously though thanks for trying i’m gonna contact my hosting plan and see if they can tell me what is going on. All i can work out is that the site is lookin for wp-404-handler.php for every post and page in my site now and i can’t work out where this rule has been set. I only got this windows hosting plan cos it was the cheapest and now i know why!!
cheers for trying mate
[...] I wrote to enable permalinks for Wordpress on IIS since I put it up on the site. Just recently, Einar Egilsson posted an extremely helpful bit a code in the comments. It’s a much better and cleaner way of [...]
[...] page that will interpret the mod rewrite for you this is for wordpress but will give you the idea tech.einaregilsson.com Blog Archive Pretty Wordpress Permalinks on IIS [...]
I followed the instructions to a T but all I get is a blank page
I hope there’s a workaround to this.
I found the php.ini file in the directory’s root folder. Is there something I can do it to rid the blank page? I read that Trevor did something to his but it doesn’t sound clear what must be done. Truly appreciate if someone could assist me
Hi
I’m not sure what the problem is. You could try commenting everything out of the wp-404-handler.php file and just putting in ‘Hello world’ or something and see if that shows up.
I don’t know what Trevor did, but I’ll email him and ask, if he replies I’ll post it here.
I tried again last nite and it didn’t work… then I tried again this morning, and bam! It works!! Somewhat. Still have a problem. I seriously have no clue… But I notice that your downloadable php file and the code in the box are not the same although they both work. Could you please tell me which one is the most reliable one?
Ok, now my problem is this… When I click on a pretty permalink, it keeps taking me to the index page instead of the particular post. So there’s no way someone can make a comment. I’ve tried deleting cache and used the other set of codes, but still no luck.
I wonder if anyone is facing something similar.
The downloadable file and the text in the box should work exactly the same way. For the text in the box I just added one intermediate variable so the line wouldn’t be too long and crash into my sidebar.
Some things to consider:
1. Is your permalink structure exactly like the one in the article, i.e. /%year%/%monthnum%/%day%/%postname%/ .? And did you definitely check the ‘custom’ box in the permalink options page?
2. I would like to see if the wp-404-handler page is somehow parsing the path incorrectly. Can you try editing your wp-404-handler page and replace this line:
include("index.php");
with this:
echo $_SERVER["REQUEST_URI"];
Then when you click on a permalink you should just see a white page with one line, the path that it parsed from the 404 url.
Let me know what that is and maybe we can figure out what’s going wrong.
Hi,
i have tried the solution
whit the wp-404-handler.php but i have problems.
When i click on a permalink i see only the “Error 404 - Not Found” page from the template.
when i replace this line:
include(”index.php”);
with this:
echo $_SERVER["REQUEST_URI"];
i see a blank page whit:
;http://www.jonioincorto.it/2007/09/25/le-foto-della-rassegna-2007-3/
(is correct that the line start with ; ?)
Any can help me?
Hi
IIS must be giving you some different format for the url. Try this:
Let me know if it works for you.
Wooow!!!!!!!!!!!!!!!!
It’s work fine!!!!
Thank you very much, this is the optimal solution for IIS.
I Resume the solution for IIS:
All you have to do is create a 404 page (wp-404-handler.php) and put the following 4 lines in it:
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:
1. Create the file wp-404-handler.php in your base Wordpress folder.
2. Set your sites 404 page to point to the wp-404-handler.php url. Most control panels at web hosts allow you to do this. If you’ve got the option to select between FILE and URL then choose URL.
3. Go to Options -> Permalinks in your Wordpress admin page, and choose an appropriate structure for your links. I chose Custom with this pattern:
/%year%/%monthnum%/%day%/%postname%/
4. Enjoy!
Thanks for all einar.
Bye bye
Sc@rob
Thank you for a simple and effective solution, it worked perfectly.
Hi Einar,
I did all of this:
“1. Create the file wp-404-handler.php in your base Wordpress folder.
2. Set your sites 404 page to point to the wp-404-handler.php url. Most control panels at web hosts allow you to do this. If you’ve got the option to select between FILE and URL then choose URL.
3. Go to Options -> Permalinks in your Wordpress admin page, and choose an appropriate structure for your links. I chose Custom with this pattern:
/%year%/%monthnum%/%day%/%postname%/
4. Enjoy!”
When I click on the default “http://example.com/?p=N”, it works fine. It goes to the content of that page. But when I change it to “/%year%/%monthnum%/%day%/%postname%/”, the permalink looks pretty, but it sends me to the 404 page. Is there something wrong?
Thanks!
You might be having the same problem as scarob had, see the comment thats two or three comments above yours. Try to modify your wp-404-handler.php according to this:
http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/#comment-132
Thank you! It’s working great now!
[...] http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ 9月26日付のコメントの中!にありました。 [...]
Thank you for the pretty permalinks! I had spent 4 hours before I reached your page and the entire thing took less than 60 seconds!! It is PERFECT!!
Thanks Again!!
[...] I wrote to enable permalinks for Wordpress on IIS since I put it up on the site. Just recently, Einar Egilsson posted an extremely helpful bit a code in the comments. It’s a much better and cleaner way of [...]
Just to say thanks for this. It didn’t work first time when I used the WordPress Date & Time option. But, once I took the index.php part out, it started working. Really good news since neither the php.ini or IIRP mod_rewrite methods worked for me. Thanks again.
Hello,
I have WordPress with /index.php/%category%/%postname%/ but I don’t want to have this. I hope remove “/index.php/” then I removed it, I created wp-404-handler.php on the website root, but It doesnt work!
1) I did all steps above, but its impossible.
Someone can help me?
Windows 2003, IIS6, WordPress 2.3.1
Thanks a lot!
Hi
Did you set your 404 page to point to wp-404-handler.php?
What is the message you get, for instance if you go to http://yourdomain.com/2007/07/07/some-post-title ?
Do you get a blank page, an error, or something else?
Give me some more info and then maybe we can figure something out.
-einar
Einar, excellent work — I’ve been looking for the IIS solution to this problem for a while. At first, this worked, but only with ‘index.php’ preceeding, however, your re-code for scarab solved it. Thanks again!!
Hi einar,
I’m getting blank pages whenever I click on a post. It doesn’t matter how I set the permalinks. Whats even more weird is that the solution works on one domain, but not the other - go figure!!
The working domain is http://www.riverlandpages.com the non-working domain is http://www.go.id.au.
Are you able to offer some advice to get the non-working domain working??
I’ve tried the file variation above - without success.
Gary
Hi Gary.
Is the non-working domain hosted on the same server as the non-working domain? There are quite a few people that get the blank page problem, I think it must have something to do with some IIS settings or something. I don’t really have much advice to offer you, other than to try one step at a time, for instance first try having the wp-404-handler.php only include the text ‘hello world’, and see if you get that working as your 404 page. If that works try doing ‘echo $_SERVER['REQUEST_URI'] and check what that gives you and so on. See where the problem starts to occur.
Einar,
I can discover the issue:
I have wp-404-handler.php with this:
But it doesnt work with PHP 5.2.4, PHP debug said: Parse error: syntax error, unexpected T_INCLUDE, expecting ‘,’ or ‘;’ in E:\Webspace\raddzh\mydomain.net\blog.mydomina.net\www\wp-404-handler.php on line 8
Line 8 = include (’index.php’) but if I remove or comment this line appear this other error:
Warning: strpos() [function.strpos]: Offset not contained in string. in E:\Webspace\raddzh\mydomain.net\blog.mydomina.net\www\wp-404-handler.php on line 4
Do you have any idea? Really thanks!
IIS 6 + PHP 5.2.4
P.S.: It is my wp-404-handler.php
Remove the ? for put the code here.
OK, I cann’t post the code here, but its the same that above. http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/#comment-132
Hi Robert. Change your wp-404 handler to include only this line:
<?php echo $_SERVER['QUERY_STRING']; ?>
Let me know what that prints out and then I can maybe help you.
Hi Einar,
Wiith your code echo $_SERVER[…. then appear or print: /wp-404-handler.php
Thanks for any help.
Hi Einar, I’m having the same problem as Robert. I have put Hello world, and it showed up, i then put , and it went back to a blank page. i really have no idea what to do anymore, seems like every time theres a solution, it ends up failing, please help!
I put and it went to blank again
?php echo $_SERVER[’QUERY_STRING’]; ?
I GOT IT, ok, for those getting the blank page, it is because your server is running on PHP 4.4.3, simply change it to PHP 5.2.0 by logging into your plesk or cpanel, and the original solution will work just fine!
Thanks a bunch Einar
Hi,
I’m using the code given in http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/#comment-132
But my site hangs when I access the homepage. On echoing _SERVER['REQUEST_URI'], I got a blank page with just,
/Index.php
I didn’t try accessing the post pages. Even the homepage is not showing up.
Am I missing something?
Regards,
Karhtik
Yemkay.com
Thanks Einar and Dan.
I got it worked. My PHP version was the culprit. It started working after setting it to 5.2
Regards
Karthik
http://www.yemkay.com
Hello,
What is the solution for PHP 5.2.4? I have PHP 5.2.5 but the script doesnt work.
Thanks!
[...] a third 404 redirect based [...]
[...] 原文连接:http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
I’m amazed.That was so easy to do AND it worked!
Thanks for providing this solution.
Einar,
I still have some problem. My homepage doesn’t show any posts with this code. Everything else works fine. Pages, posts, category pages all coming up but not the homepage. This is my permalink option,
/%category%/%postname%/
Thanks for all the help,
Karthik
Hi,
Another clue… My homepage shows posts only when I append “/index.php” in the URL address. Simply http://www.yemkay.com doesn’t bring up any posts.
On echoing “$_SERVER["REQUEST_URI"];”, I dont see the echoed string on accessing the homepage. Instead I see the homepage with “Not Found” error. It seems the page wp-404-handler.php is not getting the control when I browse the homepage.
Regards
Karthik
I’d like to try this, but in my situation I’ve a regular site that the blog is a part of. So any 404 redirects send unavailable pages to whatever the redirect points to. I’m guessing it will happen with this too. Any workarounds? My host allows URL. Also does it work with 2.3.1?
If you request an unavailable page that doesn’t map to any post in your blog then you should get a real 404 page using the 404 template from your WP Theme. So as long as you’re ok with your WP 404 page being the 404 page for your whole site you should be fine. Try going to http://tech.einaregilsson.com/doesnotexist that shows you my 404 page for example.
OK I got rid of index.php & prettified my permalinks. However I get a blank page for any legit Bad Request. I know many people asked about that here, but as I said, I’ve 2 default pages: index.html & index.php.
In fact I had to put wp-404-handler.php in my domain for the redirect to be recognized. In other words my site isn’t only a blog. Don’t know if this is clear as I’m a total layman here.
I really appreciate that you respond & this isn’t some dead script. I’m almost there but I’d like a real 404 page to show for my visitors when appropriate. When I tested what you wrote above, I didn’t get the 404 template because my blog is part of my domain and not my domain. I’d rather get a traditional 404 result, but would trade that over not having pretty permalinks.
Where is the WP 404 template supposed to be? Perhaps I need to do what you did to get that 404 message. And if you can think of a standard 404 page solution in my case, that would be great.
Was also curious is this solution affects SEO in any way, i.e., will Google still find me just as well. And the 404.php wherever it is or it’s supposed to go, how do I create it if it’s not there? Thanks again…
[...] http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
The blank page seems to be a browser issue. In most browsers you get the blank page but not all.
[...] a Windows 2003 server! I done a lot of searching and digging, but finally found this technique on Einar Egilsson’s Blog. The solution uses a custom 404 handler to complete the redirecting. Simply by adding this custom [...]
Hey dude just to let u know that I spend about 10 h trying solve this problem, till I found your article, TKS A LOT FOR THE TIME U SPEND DOING IT !
“KISSES” FROM RIO DE JANEIRO
Can anyone help me get this working.
Blog http://www.teamisportz.com/blog/
Link to http://www.teamisportz.com/blog/2008/01/07/welcome-to-our-blog/ doesn’t work.
Here is what I setup for 404 - 3 different 404 options
/teamisportz/blog/wp-404-handler.php
Do I need to do anything to php.ini file?
It appears I have it working now?
http://www.teamisportz.com/blog/index.php/2008/01/07/bcs-championship-game/
Looks like it links correctly. But my RSS Feeds are not getting updated so I wonder if my permalinks are correct or not?
Hi Jim
It doesn’t seem to work correctly for you, the link you give in your latest comment includes the /index.php/ which is what this fix is supposed to get rid of.
Maybe there’s a problem because you’re blog is under /blog/ ? I don’t think that should be a problem though, so I’m not sure why it doesn’t work properly for you.
[...] Después de probar muchas formas para conseguir unas urls bonitas para wordpress corriendo en un servidor IIS di con la solución en la siguiente direcciónhttp://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
As per the code in this comment http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/#comment-132, I get /Index.php on echoing $_SERVER["REQUEST_URI"];
Is this the expected behaviour?
My permalink structure is /%year%/%monthnum%/%day%/%postname%/
None of the solutions seems to be working for me. Please guide.
Hi Karthik
Do you get the /Index.php when trying to see your homepage? You earlier commented that everything else worked for you. Or do you get it on every page?
Yes Einar, I get it while viewing the homepage. Is it the expected behavior?
With the complete code, I get just the blank page (on accessing the home page).
has anyone else noticed that these 404 redirects to make the permalinks work break most of the contact forms for WP? (besides giving me white pages for 404s)
I tried using these and have gone MAD for the last 4 days figuring out why not a single contact form plugin works… Contact Form 7, cForms, contact forms and many others just won’t post the form when doing this…
I blamed the plugins at first but then noticed when I created a new page and pasted the same form in them, on a /?page_id=XX style of page (noticed while doing the preview, the pages keep the old type links, after published they use the slug)… the same form that didn’t worked for the last 4 days started working, until I tried to access the page via the /contact/ link, which broke it again…
is there any other solution to permalinks on IIS that is not a 404 redirect? guess I can’t have my cake and eat it too huh?
http://www.edgarciadesign.com/contact/ wont work…
change permalinks to:
http://www.edgarciadesign.com/?page_id=76 (won’t work now) and the form works… many plugins do the same, so changing plugin wasn’t a working solution for me…
fix for above:
http://www.edgarciadesign.com/?page_id=76 and the form works… (won’t work now, it has been published to /contact/) many plugins do the same, so changing plugin wasn’t a working solution for me…
Hi Ed
I haven’t used any contact plugins myself so I haven’t noticed them breaking but I’m sure using this method breaks various plugins. For each plugin that breaks you’d probably have to dig into the source code and try to see how it works and if it can be modified to behave correctly with this method.
This method, even though it mostly works, is just a big hack. If you control your own server you can install one of the many IIS mod_redirect plugins which should work without problems. If you however have shared hosting where you have no control over what’s installed on the server then you have to resort to hacks like these.
[...] tech.einaregilsson.com » Blog Archive » Pretty Wordpress Permalinks on IIS - [...]
Thank you! Thank You! I used the scarob solution from 09/26/07 and it worked perfectly! Now even real 404 pages redirect to within my template. Thanks again.
Thanks for the post this solution worked perfectly first time on my bangle blog at http://www.banglebangle.co.uk
[...] 一大 不一樣],2) 轉址的code有錯。 可是…我明明只是照著 “einar的教學” [...]
Would there be a way to put ‘exctptions’ into this method? it seems as if Simple Forums for Wordpress doesn’t work with this redirect. So, excluding http://www.domain. com/forum would be nice to do. Possible?
Hi Matt.
Do the simple forum urls depend on the value of your blog post url format? If not I don’t see why this would be a problem. Do you have a domain with a simple forum that i can see?
[...] pay $150 just to have my wordpress urls look nice. I searched around a bit, and found a good site: http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ which was pretty much what I wanted to do, apart from one little problem that [...]
Hi,
it didn’t work until I deleted http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/
Can you tell me what I did?
Thanks
Sry, I meant $_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
[...] Stand: Permalinks per 404 Error Page [...]
I have a problem. I’m using Wordpress as a CMS/blog. And I installed this hack for “Pretty Wordpress Permalinks on IIS”
For some reason this hack disrupts WP’s ability to display my designated “home “page.
Otherwise, all of my other pages and blog entries show up just fine with their “pretty permalinks” enabled.
Once I revert to the default WP permalink structure, the “home” page becomes viewable again.
My set-up is as follows:
WordPress address (URL): http://www.thecanadiangeek.ca/wordpress
Blog address (URL): http://www.thecanadiangeek.ca/
Front Page: Home (http://www.thecanadiangeek.ca/)
Post Page: Blog (http://www.thecanadiangeek.ca/blog)
Also…
I’m not sure if this is related to the hack, but I have a blog entry with quotation marks in the title, which produced this unusable URL:
http://www.thecanadiangeek.ca/blog/ 2008/04/04/did-she-say-”doodie”-or-”duty” /
Any thoughts?
I figured a way to get rid of the “blank page” issue when there is a 404 error not related to the WordPress blog.
I modified the file like this
I just searched the string for the name of my sub-directory the blog is located in. If it is not there, then I do a re-direct to my actual 404 page because I can assume it is not a WordPress page call.
Oh, my last post didn’t take the example code.
Here is another try
$_SERVER['REQUEST_URI'] = substr($_SERVER['QUERY_STRING'], strpos($_SERVER['QUERY_STRING'], ‘:80′)+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
if(strpos($_SERVER['REQUEST_URI'],”blog”) == 0){
header( ‘Location: http://www.pacebutler.com‘ );
}
include(’index.php’);
Hi Einar,
This is a nice elegant solution.
I have followed the instructions and all seems to be working the only problem I am having is the home page for my blog has an index.php include and this is displaying incorrectly.
If I type in http://www.orangetree.com.au/articles/index.php all works fine but once I change the permalinks strcuture the home page link becomes http://www.orangetree.com.au/articles and this does not display correctly.
Is there anything I can do to correct this?
[...] instead of ?p=123] doesn’t work properly. I’ve used the hack-ish technique described at Einar Egilsson’s Site to get it working for the moment, I’m going to try and futz around with it a bit more to get [...]
Hi Einar,
Thanks for your solution. I have the same problem of John (two comments above). When I put my URL directly there is no posts. If I put echo $_SERVER["REQUEST_URI"]; I just get a blank page.
Thanks.
Hi John and polyphony. Unfortunately I don’t really know how to fix the blank page issue except maybe trying some of the things other people have talked about earlier in the comments. sorry.
Finally I had to create a page that redirects to my index.php but many things doesn’t work properly. Now I can’t edit my template pages, I can’t see my about page and many plugins had to be configured again.
But it works.
This is a good workaround and I’m currently using it on several sites, but one problem I’ve noticed is that the values in the $_GET and $_POST variables don’t get passed to the final page. They got discarded inside wp-404-handler.php. You can use $_SERVER['REQUEST_URI'] to get the $_GET variables, but you have to manually parse them out.
Has anybody found a solution for this?
Ian, I have just come to the same horrifying truth. POST and GET are ruined so things like comment forms and such don’t work.
Einar … is this current blog running using this technique? Evidently *your* comment forms work
Scratch that, comments always post to a specific .php page and bypass this “filter” … however plugins that use POST or GET stop working
I guess you could modify wp-404-handler.php and doing something like
while(list($key, $value) = each($_POST))
{
echo ”;
}
But then you’d still need to submit the form to the new page. You could do that with Javascript, but it’s not very elegant.
Let’s try that again…
while(list($key, $value) = each($_POST))
{
echo ‘<input name=”$key” value=”$value” type=”hidden” />’;
}
I seem to be getting a different problem than anyone else. I’m able to redirect my 404s to wp-404-handler.php and set up permalinks, but when it actually goes to a post on WP (and therefore goes to wp-404-handler.php) I get a firefox message saying “Redirect Loop - Firefox has detected that the server is redirecting the request for this address in a way that will never complete.” The address bar at this point points correctly to http://www.robertl33t.com/wp-404-handler.php. Any ideas?
Thanks,
-Robert
Ah, nevermind! It was my own fault for putting two things on the same line in my .htaccess file. Thanks anyway!
[...] http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/ [...]
Hi Einar,
I created the 404.php and place at my domain root. I also gave the error page as http://www.mydomainname.com/wp-404-handler.php as the error file
But still the pretty permalink (/%year%/%monthnum%/%postname%/) is not working.
My host is http://www.ixwebhosting.com having IIS 6. I am using Wordpress version 2.5.1
Thanks and Regards,
Vijay
@Vijay: What do you get when you try to access a page? Do you get a blank page, a 404 page? Does the url in your browser change to http://www.mydomainname.com/wp-404-handler.php ?
Hi Einar,
I am not changing to http://www.mydomainname.com/wp-404-handler.php. I am getting my pretty permalink only. And I am getting page cannot be found 404 error.
please visit http://www.vijayforvictory.com and advice
Thanks and Regards,
Vijay
Hey, man. It solved my problem in the development machine.
2 days from now i will try in the “live” production one!
Thanks for the script!
Celso Bessa
Hi Einar, Thanks for the info. It worked for one of my blogs. But I have got more than one blog hosted in the site. And only one control panel settings to be changed. So when I put the wp-404-handler.php into one of the subdomains the other blog url does not get redirected to its individual posts. I guess it searches the same folder I use in the control panel. Is there any way to solve this?
Thanks in advance.
Cris
Hi Einar,
It is working fine. My problem was the error page url is not properly set. After raising this with the hosting support it is done.
Now I am able to see my pretty permalink ( /%year%/%month%/%postname%/ ) working fine.
After a long struggle, there are no words to explain my happiness. Thanks a lot Einar for a wonderful tip.
Thanks and Regards,
Vijay
Ok, it’s alive and running: http://www.brq.com
Pretty permalinks on IIS.
Thanks man!
[...] Regilsson - o post que me permitiu usar permalinks no WordPress rodando no Microsoft Internet Information Service 6 e o cara que escreveu o post que resolveu meu problema com o PHP no IIS em máquina [...]
I battled 2 days with various IIS rewrite solutions, permissions and .dll before practically abandoning the whole thing. This workaround works like a treat so far. Great work.
I had a problem where if the page didn’t exist, I would just get a blank page instead of the theme’s 404 page. For some reason echoing something in wp-404-handler.php fixed it. Here’s my new wp-404-handler.php
<?php
echo ““;
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
require_once(’index.php’);
?>
I tried everything and nothing works. The only thing that my php version is 4.4.7..guess I gotta try to get my ISP to upgrade. I need help!
I just tried it again and I get a blank page or Bad URL.
[...] use Pretty Wordpress Permalinks on IIS when I need to install WP on a windows server, but on one host I ran into a problem where I would [...]
Er, that should be
<?php
echo “<!– If the page doesn’t exist I get a blank screen unless I echo something –>”;
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
require_once(’index.php’);
?>
Nothing works!
it redirects me to wp-login.php, for some reason :/
oh, thanks, ian. i added echo and ot works now.
Well done Einar! This works well and I appreciate it immensily!
Great!
I added the wp-404-handler.php and set it as the custom 404 page in my control panel.
If i use permalinks i still get a CGI error: The specified CGI application misbehaved by not returning a complete set of HTTP headers.
If if type the direct URL of the wp-404-handler.php page then I resolves to the home page of my blog ……
any ideas on how to resolve this?
Hi Jaco
I’ve never heard of that particular problem. What headers are missing? Does the response return any text or just headers?
[...] lead me to einar’s post Pretty Wordpress Permalinks on IIS and with some modifications, I got it to work. It takes the port number to find the size but my [...]
Hi
I seem to be having some weird problem.
When I use the code that you have above, everything works fine …. except the home page comes up with “Sorry, no posts matched your criteria.”
All my pages and links work no problems i.e. if I click on a category all the posts appear and if I click on an individual post all links are “pretty” - its just seems to be the home page that comes up with ” Sorry, no posts matched your criteria.”
Any ideas ? When I revert back to “/index.php/%year%/%monthnum%/%day%/%postname%/” –> all posts work again on the home page ?
Really appreciate any help ?
Thanks
Hi Andy
Is your blog in a subfolder or at the root of the domain? Shouldn’t matter but it’s all I can think of. Is your default page set to index.php? That might well be the problem. Other than that I’m not sure, what is your url?
Hi Andy,
I had that same issue, my query_string did not include the port so I replaced that (’:80′) with ‘.com’ and changed +3 to +4. I recently blogged about it.
Hopefully, those changes will help you.
Hi Edgar,
I tried that and it didnt seem to help.
I’m really confused as it seems that all pages work except the main page ?
Any more ideas as I would really appreciate the help!
Thanks
Hi Guys,
I have the same issue.
My blog is at www (dot) timdavis (dot) com (dot) au
If you click on the page “23332234234″ - redirects work. But on the “home” page nothing appears. If you click on the “uncategorized” category - then all posts appear ?
I cant for the life of me figure out the issue. The posts just dont want to appear on the main page ?
Any help ?
Cheers
On my host (GoDaddy), I can only modify the 404 page for the entire site, which includes multiple domains and multiple subdomains. Obviously, using a single 404 is not feasible. When I was running my site on Linux it was easy enough to use .htaccess and ErrorDocument to specify the applicable 404 page to the site, but I’m unsure if there is a way to use a custom 404 for each subdomain on a Windows host. Am I SOL??
Hey Guys,
Any idea’s re this ? Really looking for some help ?
Thanks
Hi Tim
My best guess is that the default page for your site is not set to index.php and that might be causing these problems. It works fine if you explicitly set it to http://ourdomain.com/index.php .
Have you checked whether your control panel at your host allows you to set default pages? Could it be set to something like ‘default.aspx’ or something like that?
Even better, try adding this line to your wp-404-handler.php
echo ‘REQUEST URI: ‘ . $_SERVER['REQUEST_URI'];
after all the other lines, and let me know what it spits out when you go to your home page. I think what must be happening is that this variable has some garbage when you open the home page, causing the site to look for a page named that and failing.
Let me know
This is a great solution and it’s been working well for me. Thanks!
On a related note, I can’t actually get my permalinks to appear the way I want them to. I’ve set them up to be %postname%.asp (yes, I want the .asp extension). WordPress ignores structure and cuts off the .asp part and displays the URL without a trailing slash. I’ve tried other extensions too and I’ve disabled all plug-ins in an effort to diagnose the problem. No luck though. Any ideas?