Last Comments

snorkel (Data Warehouse / …): Oracle seems like a huge …
frak (Article Bot is fi…): Well thanks for being the…
random (Article Bot is fi…): Curious Statement from th…
frak (Article Bot Spyin…): For the answer see this u…
Bob (Pivot 1.30 Alpha.…): And this is what a commen…

Archives

01 Nov - 30 Nov 2007
01 Jun - 30 Jun 2007
01 Dec - 31 Dec 2006
01 Nov - 30 Nov 2006
01 Jul - 31 Jul 2006
01 Jun - 30 Jun 2006
01 Apr - 30 Apr 2006
01 Mar - 31 Mar 2006
01 Feb - 28 Feb 2006
01 Jan - 31 Jan 2006
01 Dec - 31 Dec 2005
01 Oct - 31 Oct 2005
01 Sep - 30 Sep 2005
01 Aug - 31 Aug 2005
01 Feb - 28 Feb 2005
01 Jan - 31 Jan 2005

Miscellany

Powered by Pivot - 1.40.5: 'Dreadwind' 
XML: RSS Feed 
XML: Atom Feed 

« Siggraph Best-Of 2005… | Home | New site coming »

Port PATH_INFO to mod_rewrite style SEF URLS

I've never got round to actually writing about code much on this blog - till now.  I've been updating a PHP directory system (because I will be launching one soon) that was written some time ago for PHP4.  That system supports SEF (Search Engine Friendly URLs) in this style:    
www.example.com/index.php/get/varables/like/this
This was done using this PHP feature: $_SERVER['PATH_INFO']
Now I want a better keyword saturation (hey - index.php there is NOT helping!) by using Apache's mod_rewrite feature (there is something similar for IIS by the way but its a third party module) so I get a URL that looks like this instead:
www.example.com/get/varables/like/this
Its pretty easy to do but this is the code change I made:
//$path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
$path = substr( $_SERVER['REQUEST_URI'], strrpos( $_SERVER['SCRIPT_NAME'],'/' ));
The old code is the commented line above.

Now to support this the last thing that is needed is (hats off to Mambo who use this widely) is the require directives in the apache config files or the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
This code does nothing for a real file/directory but for everything elses passes the request to index.php
Cheers



No comments:


No trackbacks:

Trackback link:

Please enable javascript to generate a trackback url


  
Remember personal info?

/ Textile

this is to stop spam bots causing me pain.
 

  (Register your username / Log in)

Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.