I want to convert this url:
module-apple-get.html?term=st
to
file.php?module=apple&func=get&term=st
I ‘ve wrote this code in .htaccess file:
RewriteRule ^module-apple-get\.html?term=([^-]+)$ file.php?module=apple&func=get&term=$1 [L,NC,NS]
but it doesn’t work.is it wrong?
The
RewriteRuledirective doe not work with query string directly therefore your rule will never work.Here are few approaches.
1) This will do the rewrite if
/module-apple-get.htmlis requested and will append existing query string to the new URL. This means, that if you request/module-apple-get.html?term=st&some=another_paramit will be rewritten tofile.php?module=apple&func=get&term=st&some=another_param. This is a safer and recommended approach.2) Another approach is to ONLY rewrite if requested URL has
term=stPRESENT:This will rewrite if you request
/module-apple-get.html?term=stbut will do NOTHING if you request/module-apple-get.html?some=another_param.3) Yet another approach is to ONLY rewrite if WHOLE requested URL matches:
This will rewrite if you request
/module-apple-get.html?term=stbut will do NOTHING if you request/module-apple-get.html?term=st&some=another_param.P.S.
[NC],[NS]etc)./beforefile.php(depends on your setup, where this .htaccess is located etc)