Forum Moderators: phranque
# If query does not contain foo=bar
RewriteCond %{QUERY_STRING} !foo=bar&?
# but does contain?bar&<anything>, <anything>&bar, <anything>&bar&<anything>, or only bar
RewriteCond %{QUERY_STRING} ^(.*&)?bar(&.*)?
# then remove bar and insert foo=bar in remaining query string (on domain home page only)
RewriteRule ^$ http://www.example.com/?%1foo=bar%2 [R=301,L]
Jim
RewriteRule ^\?([^=&]+)$ /reel?list=$1
I escaped the "?" but it does not seem to match the question mark.
If I change "\?" to e.g. "x", all works fine though.
RewriteRule ^x([^=&]+)$ /reel?list=$1
How can I mach a single "?" in a pattern?
The query string is not included in the URL-path examined by RewriteRule. Instead, Apache places everything after "?" into the variable %{QUERY_STRING} and handles it separately from the URL.
To further clarify: A query string is not part of a URL. Instead, it is data attached to a URL to be passed to the resource at that URL.
If you request "http://example.com/page.php?foo=bar" from your server, then
http is copied to the variable %{SERVER_PROTOCOL}
example.com is copied to %{HTTP_HOST}
page.php is copied to an internal variable testable by RewriteRule
/page.php is copied to %{REQUEST_URI}
foo=bar is copied to %{QUERY_STRING}
The "?" is dropped, and does not appear in any of the above variables; it serves only as a delimiter between the URL and the query string.
You may test the original request line sent by the browser, which look something like this
GET /page.php?foo=bar HTTP/1.1
by using
RewriteCond %{THE_REQUEST} <regex pattern here>
but the code I posted above is simpler.
Jim