0

I have a link like this: http://localhost/dimi/home?go=post&app=tagline&post_id=222

How do I rewrite the url to look like this: http://localhost/dimi/home/post/tagline/222

What tried is:

RewriteEngine On
RewriteRule ^home$ home.php [L]
RewriteRule ^home/([^/]+)/?$ home.php?go=$1 [L,NC]

I just want to hide the variables for security purposes.

Thank you

1 Answer 1

1

Try it like this in dimi directory.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\d]+)$ $1.php?go=$2&app=$3&post_id=$4 [QSA,NC,L]
Sign up to request clarification or add additional context in comments.

2 Comments

It worked but I love it when you can explain your answer.please
We capturing every match from url and putting those caputre groups $1,$2.. to the respective field of original url in that way we are internally rewriting the url to original one, you can accept this as an answer if it helps you. more learning httpd.apache.org/docs/current/mod/mod_rewrite.html

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.