-1

I am trying to redirect below example url. but unable to get it right please help me.

suppose url is www.example.com/user?id=abcdef (File name user.php)

And i want to redirect it to www.example.com/user/abcdef.

i have tried RewriteRule RewriteCond query string as i guess its wrong.

below is what i have written.

RewriteRule ^user?id=/(.)?$ user.php?id=$1.*

Please help me to solve it. thanks in advance.

  • 1
    Does this answer your question? [How can I match query string variables with mod\_rewrite?](https://stackoverflow.com/questions/2252238/how-can-i-match-query-string-variables-with-mod-rewrite) – CBroe Sep 28 '21 at 09:07
  • Does this answer your question? [How to implement friendly URLs without breaking images, CSS and JavaScript?](https://stackoverflow.com/questions/69325941/how-to-implement-friendly-urls-without-breaking-images-css-and-javascript) – MrWhite Sep 28 '21 at 11:21

1 Answers1

0

This probably is what you are looking for:

RewriteEngine on

RewriteCond %{QUERY_STRING} (?:^|&)id=(\w+)(?:&|$)
RewriteRule ^/?user\.php/?$ /user/%1 [R=301,L]

RewriteRule ^/?user/(\w+)/?$ /user.php?id=$1 [QSA,L]

It externally redirects requests to URLs that use technical notation and internally rewrites requests using clean syntax.

arkascha
  • 41,620
  • 7
  • 58
  • 90