views:

47

answers:

3

I would like to redirect to https using mod_rewrite only if certain conditions are met:

If the URL does NOT contain the word 'administrator' AND the URL DOES contain the string 'xyz' (in any part of the URL, including the querystring)

This does not seem to work:

RewriteCond %{REQUEST_URI} xyz [NC,OR]
RewriteCond %{QUERY_STRING} xyz [NC]
RewriteCond %{REQUEST_URI} !administrator [NC]
ReWriteCond %{HTTPS} != on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R,L]
A: 

Try this rule:

RewriteCond %{THE_REQUEST} !administrator
RewriteCond %{THE_REQUEST} xyz
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Testing the request line in THE_REQUEST is easier as it contains both the path and query. But make sure your xyz is not part of the method or HTTP version.

Gumbo
A: 

I'm trying to do the same thing as Russ is. I tried Gumbo's suggestion - in addition to a number of other attempts - but this still doesn't force the URL that includes xyz to https.

A: 

I ended up using a coding solution as I could not get it to work with mod_rewrite. :(

Russ