I've come across plenty of questions dealing with redirecting based on HTTP queries and of course matching partial parts of URLs however not both.
My directory structure looks like the following:
The rewrite that I have works fine except it blocks the directory in the second list item:
RewriteCond %{REQUEST_URI} !\.xml$
RewriteRule ^[^/].*/themes(.+) themes$1 [L]
Unfortunately both demo/themes/?ajax=1
and themes/?ajax=1
are both requested with the ajax
HTTP query. However only the demo/themes/
is requested with a foo
HTTP query.
So in short how do I rewrite my rewrite
to only apply if the ajax
http query is present and simultaneously the foo
http query is not present?
You can use rewrite rule like this:
# when ajax=<whatever> query parameter is present
RewriteCond %{QUERY_STRING} (?:^|&)ajax= [NC]
# when foo=<whatver> is not present
RewriteCond %{QUERY_STRING} !(?:^|&)foo= [NC]
# when URI is not ending with .xml
RewriteCond %{REQUEST_URI} !\.xml$ [NC]
# rewrite handler
RewriteRule ^[^/].*/themes(.+) themes$1 [L]