Support » Plugins » Problem with permalinks and 404 redirect script

  • Hello.

    I’ve recently began a project for a small company that involves wordpress and IIS, after some agonizing hours searching in google I managed to get permalinks working with a 404-redirect script(this one), works perfectly with posts, but when I try to access any link other than a ?p one(for example, information or category) it shows a wordpress 404 error, not a navigator/web server one, but a wordpress page with 404 in it.

    I’m ussing the default theme.

    Any idea on how to resolve that? I would really prefer avoid getting much into WP code since this is a really small project with a small time frame, but if necessary I have some experience with php.


Viewing 7 replies - 1 through 7 (of 7 total)
  • From what I can see that code should work. have you read this post If none of those options work get back to me with the url of your site and I can try and work out whats going on.

    Thanks for answering so fast.

    I did read that post and tried the scripts, all of them work with the posts with also fail with the info/category/… links.

    Sadly the machine I’m working on is on a LAN server without connection to internet so I can’t show you the error, if there is any info I could gather and post please tell me and I will do. If hat isn’t enough I’ll try to get my hands on another IIS server(I’m not sure if it will be possible) so I can replicate the error.

    Again, thanks for the help.

    This bit of code in wp_settings.php is the bit that matters:

    // Fix for IIS, which doesn't set REQUEST_URI
    if ( empty( $_SERVER['REQUEST_URI'] ) ) {
    	// IIS Mod-Rewrite
    	if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
    	// IIS Isapi_Rewrite
    	else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
    		// Use ORIG_PATH_INFO if there is no PATH_INFO
    		if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
    		// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
    		if ( isset($_SERVER['PATH_INFO']) ) {
    			if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
    		// Append the query string if it exists and isn't null
    		if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
    // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
    if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
    // Fix for Dreamhost and other PHP as CGI hosts
    if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
    // Fix empty PHP_SELF
    if ( empty($PHP_SELF) )
    	$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);

    It seems that PHP does all the IIS sorting out for you. How about just simply using


    Other than that I don’t know what to suggest.

    Hi again.

    I haven’t really looked at that part of wp_settings.php jet, but just a quick test changing the 404-redirect script with the one you suggested delivered some results (I don’t know if useful or not):

    With only “require(‘index.php’);” in the script, the posts don’t work, It gives a “there’s no entry with your search criteria” text (not exactly, that’s translated from the Spanish), the interesting thing is that now the information and category links show the same page instead of the 404 one.

    If that’s not useful, I’ll try to get into the wp_settings.php file tomorrow and do some try and error hoping to get it working without expending too much time with that issue.

    Thanks again.


    I’ve been trying for a while now and I can’t get it to work, at first I thought it was a problem only if I didn’t use “index.php” in the url, but it doesn’t work with any other option other than the default url/?p=XXX. The other WP default options (index.php/year/month/day/name | index.php/year/month/name | …).

    I’m completely lost as of why this doesn’t work, and after reading the code I’m beginning to think this is some kind of limitation of IIS, the problem is that WP is supposed to work in IIS so that can’t be it…

    Any ideas?


    I managed to get everything to run smoothly, turns out the machine I was working on had been abused in some serious ways and after reinstalling everything from scratch (windows, iis, …) wp worked perfectly from scratch, and the only thing I had to do to use permalinks w/ index.php was indeed create a wp-404-handler.php wit “include(“index.php”);”.

    Thanks again and sorry for the trouble.

    Thats very interesting, you didn’t upgrade to a newer version of IIS and PHP when you reinstalled? Well I’m glad you’ve got it sorted.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problem with permalinks and 404 redirect script’ is closed to new replies.