-1

want to remove paramters from url using htaccess My url look like this

http://localhost/details?id=179&title=abcdefghij

i want to convert it like this (or any better suggestion)

http://localhost/details/179/abcdefghij

Please help me how can i acheive it

  • 1
    Learn to use google. This question was answered many times. Open initial configuration step of any modern PHP framework and it'll have your answer. – E_p May 30 '16 at 18:14
  • Possible duplicate of [Help with mod\_rewrite and mod\_redirect](http://stackoverflow.com/questions/3917220/help-with-mod-rewrite-and-mod-redirect) – E_p May 30 '16 at 18:15
  • Possible duplicate of [How can I match query string variables with mod\_rewrite?](http://stackoverflow.com/questions/2252238/how-can-i-match-query-string-variables-with-mod-rewrite) – Matt Raines May 30 '16 at 18:30

1 Answers1

0

To convert /details?id=123&title=foobar to /details/123/foobar you can use the following rule in root.htaccess :

RewriteEngine on
#1  redirect "/details?id=123&title=foobar" to "/details/123/foobar"
RewriteCond %{THE_REQUEST} /details/?\?id=([^&]+)&title=([^\s]+) [NC]
RewriteRule ^ /details/%1/%2? [L,R]
#2 internally rewrite the requested url "/details/123/foobar" to "/details?id=123&title=foobar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^details/([^/]+)/([^/]+)/?$ /details?id=$1&title=$2 [L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115