Faux Folders from Files


/ Published in: Apache
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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

You need to login to post a comment.