I have tried lots of URL rewrite rules in .htaccess but I am stuck now. I have to change this URL:
products.php?id=31
to
products/31
I have used:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
RewriteCond %{THE_REQUEST} \s/+products(?:\.php)?\?id=([0-9]+) [NC]
RewriteRule ^ products/%1? [R,L]
RewriteRule ^products/([0-9]+)/?$ products.php?id=$1 [L,QSA]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Using this I get the following result:
products/31
But all images and CSS not displaying. Any ideas?
RewriteRule ^products/([0-9]+)/?$ products.php?id=$1 [L,QSA]
The duplicate rules should be removed so you can understand what is happening.