Remove index.php from WordPress Permalinks

10.14.2010 | 8:41 pm | Code

Sometimes it can happens when you install WordPress with the default permalink structure everything will work fine. But when you want to change the permalink to /%year%/%monthnum%/%postname%/ it creates the following url index.php/%year%/%monthnum%/%postname%/ (mind the index.php).

The reason of this problem is that WordPress doesn’t think it’s running on Apache so it doesn’t create/write to the .htaccess file. It looks at the $_SERVER['SERVER_SOFTWARE'] variable which comes back with “WebServerX” based on what phpinfo() says on your server.

So, if you edit the /wp-includes/vars.php file and change the server detection area to:

// Server detection
// $is_apache = ((strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) || (strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false)) ? true : false;
$is_apache = 1;
$is_IIS = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false) ? true : false;

It should work. Basically just bypassing the variable check and manually telling it that it’s running on Apache will remove the index.php from the url.

3 Comments »

  1. this is worked with me…index.php has been removed from permalinks settings in my admin panel…now wat should i write in .htaaccess file…because its still giving 404 error.if i m not writting /index.php

    Comment by maulik | 03.26.2012 | 10:00 pm

  2. also worked for me but same issue – 404 error and does not seem to write a .htaccess file!

    Comment by Steve | 10.12.2012 | 5:16 am

  3. not worked for me either. help !

    Thanks a ton

    Comment by Vikas Paul | 02.10.2013 | 6:25 pm

 

Leave a comment