Crag
Crag

Reputation: 107

.htaccess rewriteEngine with multiple get variables

Is there a way to change a url with multiple variables, for example this url:

index.php?p=place&c=Munich

to:

/place/munich

with .htaccess?

Upvotes: 1

Views: 87

Answers (2)

anubhava
anubhava

Reputation: 784998

You can use this rule in root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?p=$1&c=$2 [L,QSA]

Upvotes: 2

nxu
nxu

Reputation: 2272

Depending on what characters those two parameters contain, here's one for only letters (a-zA-Z):

RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)$ index.php?p=$1&c=$2

Upvotes: 1

Related Questions