简体   繁体   中英

want to remove paramters from url using htaccess

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM