Query string after .html in htaccess doesn’t work.why

.htaccess

My site is written in PHP. I have changed its urls from php to html and reconvert it in .htaccess file.

I put autocomplete jquery ui widget in a page of my site and its call to remote file to get suggested items doesn't work. Because the remote url is changed to

search.html?term=spr

I put this line in htaccess file but it doesn't matche because it doesn't consider anything after \.html.

RewriteRule ^search\.html?term=([^-]+)$ search.php?term=$1 [L,NC,NS]

I also tried

RewriteRule ^search\.html\?term=([^-]+)$ search.php?term=$1 [L,NC,NS]

but both doesn't work.

Would you help me?
Thank you.

Best Answer

You need to tell Apache to append the query string (QSA = Query string append)

 RewriteRule ^search\.html$ search.php [L,NC,NS,QSA]

^search\.html$ is a regular expression matching a literal search.html. ^ matches from the beginning, $ matches till the end and \. matches a literal dot instead of any character (the special meaning of a dot in regular expressions)

This rule...

  • Matches a request for search.html (RewriteRule ^search\.html$)
  • and rewrites it to search.php,
  • processing no rules after this one ([L]),
  • match case insensitive (e.g. Search.HTML would be rewritten too) ([NC])
  • will not be used for subrequests ([NS])
  • and will finally append the original Query string after search.php ([QSA])

For an overview of flags:

Related Topic