Forum Moderators: phranque
I have the below rule to force https for my software.
RewriteEngine on
RewriteCond %{SERVER_PORT}!443$
RewriteRule ^(.*)$ https://software.example.com$1 [R=301,L]
But my problem is I want to have other certain pages that use links like (https://software.example.com/dir/index.php?var=abc) forced back to http due to the fact that they contain some unsecure content and it causes warnings in MSIE.
I have tried to write rules to do this but i cannot seam to get it working. All help is greatly appreciated.
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{QUERY_STRING} ^var=abc$ [NC]
RewriteRule ^/dir/index\.php$ http://software.example.com/dir/index.php?var=abc [R=301,L]
You can back-reference the query var value if need be, or even the entire query, by using a parenthesized sub-pattern to match the part to be back-referenced in the RewriteCond, and then de-referencing it with %1 in the RewriteRule substitution URL. Example:
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{QUERY_STRING} ^var=([a-z]+)$ [NC]
RewriteRule ^/dir/index\.php$ http://software.example.com/dir/index.php?var=%1 [R=301,L]