Reputation: 411
I have some request parameters which I am converting to friendly URL
For example:
http://domain.com/members/girls/sort/last_reg/nick/ted/from/18/to/28/hfrom/150/hto/190/bbody/Athletic/
The parameters are dynamic so the URL could be
http://domain.com/members/girls/nick/ted/from/18/to/28/hfrom/150/hto/190/bbody/Athletic/
or
http://domain.com/members/men/nick/ted/to/28/hfrom/150/hto/190/bbody/Athletic/
The parameters are in pairs
parameter_name/parameter_value
The only thing which is constant is
http://domain.com/members/
How to transform this URL to
http://domain.com/filename.php?sex=men&pram1=value1¶m2=value2 ......
or
http://domain.com/filename.php?sex=girls&pram1=value1¶m2=value2 ......
Upvotes: 1
Views: 1706
Reputation: 784968
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
## recucrsion based rule to convert
## /members/men/n1/v1/n2/v2 to /members.php?n2=v2&n1=v1&sex=men
RewriteRule ^(members)/(girls|men)(/.*)?$ /$1/$3?sex=$2 [L,QSA,NC]
RewriteRule ^(members)/([^/]*)/([^/]*)(/.*)?$ /$1/$4?$2=$3 [L,QSA,NC]
RewriteRule ^(members)/?$ /$1.php [L,NC]
Upvotes: 2
Reputation: 1319
This may help:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ filename.php?$1=$2&$3=$4 [L,QSA]
Upvotes: 0