Ihor Patychenko
Ihor Patychenko

Reputation: 196

.htaccess RewriteRule to get pretty links 4

Sorry, maybe for stupid question, but I really have no idea how to make the following...

For example I have this link:

http://www.mypage.com/?section=orders&action=add_order

And I want to make it like this (hidding the GET param key, and separate params by slash "/"):

http://www.mypage.com/orders/add_order

Upvotes: 0

Views: 35

Answers (2)

Hariprasad
Hariprasad

Reputation: 3640

Try:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?section=$1&action=$2 [L]

Upvotes: 0

Noam Rathaus
Noam Rathaus

Reputation: 5598

Though kind of ugly and doesn't support infinite number of parameters it works:

RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$  index.php?$1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4&$5=$6

If you can write some code you can make a perl script (or any other language) redirect the user after splitting his URI parameters

Upvotes: 2

Related Questions