I am trying to use RewriteRule inorder to redirect form x page to y page.
x page got two parameters > products.php?product=$1&page=$2 (myweb.com/products.php?prod...)
y should be $1/$2/ (myweb.com/$1/$2/)
I tried this one >
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^products.php?product=(.*) $1/ [R=301,L]
just for testing, and some similiar codes like > /$1/
instead $1/
, only $1
I tried to use RewriteCond with query_string but nothing worked....
ofc that there's continue to the htaccess >
RewriteRule ^(.*)/$ $1.php [L]
and some more rules which are not relevant (I think)
Can you help me please?
Thanks.
EDIT:
After some massive searches I found the answer!
this is the answer:
RewriteCond %{QUERY_STRING} ^product=(.*)$
RewriteRule ^test.php$ %1/? [R=301,L]
now for the explanation:
first of all, added rewritecondition that will match the query string.
second I remove the query string from the rewrite rule and the $ = the continue (the query string). I also needed to add ? (question mark) at the second part of the rewriterule > %1/?
the question mark mean that I dont want to preserve the query string in the new url.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…