|

Pretty WordPress permalinks without PATHINFO

Posted on Sunday, 01 July 2007 at 10:34.

For a client I was installing WordPress, when I found out that their webserver doesn’t support PATHINFO, which WordPress needs for its pretty permalinks.

I worked around this problem by changing the .htaccess rewrite rule so that the path is supplied as normal GET parameter:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php?path=$0 [L]
</IfModule>

Then in WordPress’ index.php I set the REQUEST_URI and PATHINFO to what they should have been:

if (preg_match('/(.*)?path=(.*)/', $_SERVER['REQUEST_URI'], $matches)) {
  $_SERVER['REQUEST_URI'] = $matches[1] . '/' . $matches[2];
  $_SERVER['PATH_INFO'] = '/' . $matches[2];
}

And voilà! Pretty permalinks without PATHINFO.

Edit: WordPress doesn’t approve of custom .htaccess files and tries to overwrite them everytime the admin panel (or certain pages of it) is loaded. To fix this problem, make your .htaccess file read-only.

Comments

By Thijs Kinkhorst on Sunday, 01 July 2007 at 13:31:

Great… but what webserver doesn’t support PATH_INFO?

By Martijn on Sunday, 01 July 2007 at 22:43:

Lycos webservers, apparently! I’ve sent them two emails about it, but all they will say is:

“Wij delen u mede dat het niet mogelijk is om de PATHINFO functie aan te zetten, omdat u een Shared Hosting gebruikt.

Met een Shared Hosting hebt u beperkte mogelijkheden om uw website aan te passen.”

By Dana on Thursday, 09 August 2007 at 17:27:

Hi Martijn.
I lost that website that had your address on it.
I would like to have it. I felt like writing you today.
I like letters. We need to keep in touch.
-Dana

By jeropp on Friday, 21 March 2008 at 00:12:

tried it with my lycos hosting but still does not seem to work…are there any other options apart from accepting this problem and using the default permalinks?

great thing if it worked with you and i so wish that my frend didnt use lycos..

By serge on Wednesday, 26 March 2008 at 00:08:

Thanks a lot, it works fine on Lycos

By Antek on Thursday, 05 June 2008 at 07:39:

I didnt get it to work:
Warning: Division by zero in /data/members/paid/a/d/XXXXX.nl/htdocs/www/index.php on line 6

Warning: Division by zero in /data/members/paid/a/d/XXXXX.nl/htdocs/www/index.php on line 7

By Antek on Thursday, 05 June 2008 at 07:41:

hmm apparantly I had to put the lines in the index.php in front of the
/* Short and sweet */
define(‘WP_USE_THEMES’, true);
require(‘./wp-blog-header.php’);

Leave a comment!

Martijn loves to receive comments! Add yours by filling out the fields below.