Reputation: 21
How can I rewrite URL (i.e. remove last /
after test) using .htaccess
on php page from
from www.example.com/test/?sku=23456&qty=3
to www.example.com/test?sku=23456&qty=3
from www.example.com/page2/?page=3&emp=543
to www.example.com/page2?page=3&emp=543
from www.example.com/stream/?start=4&id=tdfcs45s&q=sat
to www.example.com/stream?start=4&id=tdfcs45s&q=sat
I tried but it doesn't work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Upvotes: 0
Views: 76
Reputation: 133458
With your shown samples and attempts please try following .htaccess rules file. We need to use THE_REQUEST
variable here of apache. Check this if this helps you, also clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s(/test)/(\?sku=(\d+)&qty=\d+)\s [NC]
RewriteRule ^ %1%2 [L]
Upvotes: 1