Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite. Default https but certain pages in http.

         

lmwood

1:31 pm on May 24, 2006 (gmt 0)

10+ Year Member



Hi All,

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.

lmwood

2:06 pm on May 24, 2006 (gmt 0)

10+ Year Member



Here is a rule I have just tried out but its still not working. Does anyone know where im goin wrong?


RewriteCond %{SERVER_PORT} 443
RewriteRule ^/dir/index.php?var=abc$ http://software.example.com/dir/index.php?var=abc [NC,R=301,L]

Thanks in advance

Lee

jdMorgan

10:08 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where did you install this code -- httpd.conf, conf.d, .htaccess, or?

Jim

lmwood

8:06 am on May 25, 2006 (gmt 0)

10+ Year Member



httpd.conf

under the correct directory where i require the rule to be implemented.

jdMorgan

12:44 pm on May 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings are not part of a URL; They are data attached to a URL to be passed to the resource at that URL. Therefore, queries are not 'seen' by RewriteRule, and must be handled separately:

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]

The changes also address the port number anchoring and query case issues.

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]

Jim