.htaccess - RewriteRule to redirect with url that got parameters -
i trying use rewriterule inorder redirect form x page y page. x page got 2 parameters > products.php?product=$1&page=$2 (myweb.com/products.php?prod...) y should $1/$2/ (myweb.com/$1/$2/)
i tried 1 >
options +followsymlinks rewriteengine on rewritebase / rewriterule ^products.php?product=(.*) $1/ [r=301,l]
just testing, , similiar codes > /$1/
instead $1/
, $1
tried use rewritecond query_string nothing worked....
ofc there's continue htaccess >
rewriterule ^(.*)/$ $1.php [l]
and more rules not relevant (i think)
can me please?
thanks.
edit:
after massive searches found answer! answer:
rewritecond %{query_string} ^product=(.*)$ rewriterule ^test.php$ %1/? [r=301,l]
now explanation: first of all, added rewritecondition match query string. second remove query string rewrite rule , $ = continue (the query string). needed add ? (question mark) @ second part of rewriterule > %1/?
question mark mean dont want preserve query string in new url.
the first part of rule should contain regular expression against server can compare request. instance:
rewriterule ^([^/]+)/? index.php?page=$1 [l]
that take http://somedomain.fake/somepage/ , redirect http://somedomain.fake/index.php?page=somepage. first part of rule matches, second part handles. rule there, "([^/]+)", regular expression match anything. if want narrow way rule works, can customize regular expression include or exclude string parts.
i suggest consider adding follow conditions above rule. ensure if file or directory matches rule exists, server not override actual files rewrite.
rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d
.htaccess , mod_rewrite voodoo, use old quote. sure research thoroughly before implementing kind of thing on live site.
--------------------- edit:
updated after discussion:
rewriteengine on rewritecond %{query_string} ^product=([^/]+)$ rewriterule ^products\.php$ %1.php [l]
or
rewriteengine on rewritecond %{query_string} ^product=([^/]+)$ rewriterule ^products\.php$ %1/ [l]
Comments
Post a Comment