views:

27

answers:

2

I'm forcing HTTPS on my site using mod_rewrite but I want to change this to HTTP for any URL with the substring com_bookmangement in the URL.

So

http://www.example.com/index.php?option=com_content&view=article&id=85&Itemid=140

will be directed to

https://www.example.com/index.php??option=com_content&view=article&id=85&Itemid=140

BUT

https://www.example.com/index.php?option=com_bookmanagement&controller=localbooks&Itemid=216

will be directed to

http://www.example.com/index.php?option=com_bookmanagement&controller=localbooks&Itemid=216

I've tried this without success:

#rewrite everything apart from com_bookmanagement to HTTPS
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_URI} !com_bookmanagement=
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

#rewrite vouchers views to http
#RewriteCond %{server_port} 443
RewriteCond %{REQUEST_URI} ^com_bookmanagement=
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]

Any ideas?

A: 

If you use ^com_bookmanagement= it will only match if com_bookmanagement= appears at the start of the string. Try it without the ^ and =. Or what I would use:

#rewrite everything apart from com_bookmanagement to HTTPS
RewriteCond %{HTTPS} !=on
RewriteCond %{QUERY_STRING} !(^|&)option=com_bookmanagement(&|$)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#rewrite vouchers views to http
RewriteCond %{HTTPS} !=off
RewriteCond %{QUERY_STRING} (^|&)option=com_bookmanagement(&|$)
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Gumbo
Based on his example URLs, he also seems to want to examine `%{QUERY_STRING}` or `%{REQUEST_URI}?%{QUERY_STRING}` instead of just `%{REQUEST_URI}`.
Tim Stone
Yes, usingg QUERY_STRING rather than REQUEST_URI with the above code solved the problem. Thanks very much!
A: 

Condition on QUERY_STRING instead of REQUEST_URI:

RewriteCond %{SERVER_PORT} !443
RewriteCond %{QUERY_STRING} !com_bookmanagement
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]
RewriteCond %{QUERY_STRING} com_bookmanagement
RewriteRule ^/(.*)$ http://www.mysite.com/$1 [R=301,L]

More on rewriting URIs with query strings here.

You