this is my apache .htaccess
setting with a search page redirect
(RewriteRule ^search/(.*)$ /index.php?c=index&m=search&keywords=$1 [L,QSA]),
if I set the search query in url without %
, it works success request without '%' but if a %
char added to the string, apache with return a bad request with % , howerver instead of adding %
but %25
, the urlencoded string of %
, success request when pre encode %
to %25
I want to know about the reason of this situation. I guess in the RewriteRule
of .htaccess
an urldecode function worked from Pattern to Substitution, that's why %
char cannot be recognized by the server, but %25
can. How can I disable this urldecode function?
Easy workaround for "disable" auto url decoding is to use Server-Variables like
REQUEST_URI
orTHE_REQUEST
in RewriteCond Directive (http://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteCond)If you use REQUEST_URI, in PHP you must use $_SERVER['REQUEST_URI']. Do not use $_SERVER['QUERY_STRING'] or $_GET, otherwise you will get the decoded url. If you want all $_SERVER doing what you need, use THE_REQUEST instead:
And we just need to put . (dot) in RewriteRule pattern and use %1 instead of $1