Reputation: 20977
In my htaccess I convert ? to # with the following:
# The below 2 lines will convert a ? to a # in the query.
RewriteCond %{REQUEST_URI} !^\/*(admin|access.php)
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*) /$1#%{QUERY_STRING}? [R=301,L,NE,NC]
What this does is convert ? to # unless the url has one of:
/admin
/access.php
So a url like the following won't get the ? converted:
http://mysite.com/access.php?login=special
However, now I have the requirement that a search parameter using the ? (not the #) be allowed to be used:
http://mysite.com/?s=somesearchstring&submit=Search
And I am floundering trying to get that to work. With the current rules the ? gets converted and I end up with:
http://mysite.com/#s=somesearchstring&submit=Search
But I need to NOT convert that ? to a #.
Any suggestions?
Upvotes: 0
Views: 22
Reputation: 51711
Change
RewriteCond %{QUERY_STRING} .
to
RewriteCond %{QUERY_STRING} !(^|&)s=.*?(&|$)
RewriteCond %{QUERY_STRING} !(^|&)submit=Search(&|$)
This won't modify ?
to #
if both s
and submit
are present. They may appear in any order they like.
Upvotes: 1
Reputation: 20977
It seems that adding the following works:
RewriteCond %{QUERY_STRING} !^s=
But I worry that my lack of clear understanding of why might result in some problems.
Here is my understanding:
If the query string
!(does not)^(start with)s=
Am I missing anything? That does, at first glance, appear to solve my problem but perhaps it is incomplete or error prone?
Upvotes: 0