1

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?

0

2 Answers 2

2

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]
Sign up to request clarification or add additional context in comments.

8 Comments

ahh yeah your script works great, but no single link in my application is now correct. Is there a way to fix this from the .htaccess?
i meant that not a single link in the whole app is correct when i open the new url :D sry
Oh I had a typo in my rule that I have fixed now. Can you try again. Also make sure to use use use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /
yeah i found the problem, there was a error with the variable that included the full http path. now its working fine. Thank you
Glad to know, can you mark the answer as accepted by clicking on tick mark on top-left of my answer.
|
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.