I want to redirect 5 pages with querystrings eg:
abc.com/index.php?id=1
should go to
abc.com/1-adasfa.html
abc.com/index.php?id=2 should go to abc.com/2-bbgbb.html
and so on.
What code should be used in .htaccess?
I want to redirect 5 pages with querystrings eg:
abc.com/index.php?id=1
should go to
abc.com/1-adasfa.html
abc.com/index.php?id=2 should go to abc.com/2-bbgbb.html
and so on.
What code should be used in .htaccess?
The “adasfa” and “bbgbb” is not possible. I suppose what you mean by this is information that is linked to the id, htaccess can’t perform database queries or anything of the sort.
To make “abc.com/1.html” go to “abc.com/index.php?id=1” you need this in your .htaccess:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).html?$ index.php?id=$1 [L]
It is possible, you just need to catch the numeric ID and the leading dash, and then give the id to index.php, like so:
RewriteEngine On
RewriteRule ^(\\d+)- index.php?id=$1 [L]
Scallio you are right, because he said index.php?id=1 should go to 1-adasfa.html, while it’s the other way around, that messed me up ^^
I’ve never thought about putting stuff in the url that you don’t actually use in your code, purely for seo reasons (I usually put actual information in the url that I also parse).
That could actually come in quite handy