All .htacces and mod_rewrite answered - examples, tips and tricks Forum Index  

All .htacces and mod_rewrite answered - examples, tips and tricks Forum Index -> Cool URLs - advanced -> Static to hierarchic: /aaa-bbb-ccc.php --> /aaa/bbb/ccc
Author Message
admin
Site Admin


Joined: 18 Jul 2006
Posts: 89

PostPosted: Tue Jul 18, 2006 10:09 am    

Static to hierarchic: /aaa-bbb-ccc.php --> /aaa/bbb/ccc

Reply with quote

My current URLS look like:
1. /about.php
2. /about-extras.php
3. /about-extras-something1.php
...
4. /solutions-something2.php
...
So I have unknown number of dashes.
I would like to have standard:

1. /about (/about/)
2. /about/extras (/about/extras/)
3. /about/extras/something1 (/about/extras/something1/)
...
4. /solutions/something2 (solutions/something2/)
...

Code:
Options +FollowSymLinks -MultiViews

RewriteEngine On

# replace all "/"s with a "-",
# ignore the optional final "/"
RewriteRule ^(.*)/(.*)([^/])/?$ $1-$2$3 [E=QR:$1-$2$3]

# when they're all gone
RewriteCond %{ENV:QR} .
RewriteCond %{ENV:QR} !/
# append .php and request the file.
RewriteRule .* /%{ENV:QR}.php [L]

Source:http://forum.modrewrite.com/viewtopic.php?t=1720
Back to top
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.   
View previous topic
View next topic
All .htacces and mod_rewrite answered - examples, tips and tricks Forum Index
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
FreeMind 1.1 Template by AU Templates