Posted By

jackkeller on 03/13/09


Tagged

htaccess apache


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

montanaflynn


Faux Folders from Files


 / Published in: Apache
 

This is a little trick I've used a few times to emulate Folders on a site and drop the extensions. In this example I'm using a PHP site but could easily be ported for other file types. One caveat to look out for is files will not always want to be called anymore from their .php and linking to new pages should be done with a href="/newpage" instead of just href="newpage".

Play with it, it's just a down and dirty method to make your urls more sef for sites not running on a cms that has this built into it.

  1. RewriteEngine On
  2. RewriteBase /
  3. RewriteRule ^admin/.*$ - [PT]
  4. # Use the above line for a folder that you DON'T want to follow these rules
  5. RewriteRule ^/?([a-zA-Z0-9-_/]+)/$ $1.php [L]
  6. # Here's where the "magic" happens
  7. # http://www.example.com/page.php - OLD
  8. # http://www.example.com/page/ - NEW

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: montanaflynn on June 18, 2009

This is just what I have been looking for! Can anyone offer a solution to the PHP linking? I think a 301 redirect would do the job nicely.

Posted By: montanaflynn on June 18, 2009

Actually this never worked out for me, I will continue my search!

You need to login to post a comment.