Forum Moderators: phranque

Message Too Old, No Replies

SEO vs. Secure Apache Rewrite Rules

Apache HTTPD RewriteRule

         

DepecheModem

9:41 pm on Nov 19, 2009 (gmt 0)

10+ Year Member



Hi guys,
I've got a puzzling rewrite rule request. I'm trying to develop a set of rules that will handle two requests that somewhat oppose one another.

First, I have a SEO request whereby all requests to HTTPS need to be '301' redirected to HTTP so that we will not have duplicate results in search engines.

Second, I have 5 forms under the same site that collect customer-sensitive information and need to be forced to be HTTPS (and excluded from the first rule).

So far, I've been unsuccessful getting the second rule by itself to work as it always creates a redirect loop no matter what I try. My last attempt:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule "^/form1.html$" "https://%{HTTP_HOST}%{REQUEST_URI}" [R=301,L]

So, simply condensed, I need a rule that will force all traffic to be HTTP except for 5 specific URIs that need to be forced to be HTTPS.

Any help would be appreciated! Thank you!

-Jay

jdMorgan

2:26 am on Nov 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your http vHost:

RewriteCond %{SERVER_PORT} !=443
RewriteCond $1 ^secure-form1\.html$ [OR]
RewriteCond $1 ^secure-form2\.shtm$ [OR]
RewriteCond $1 ^secure-form3\.php$ [OR]
RewriteCond $1 ^secure-form4\.shtml$ [OR]
RewriteCond $1 ^secure-form5\.cfm$
RewriteRule ^/(.+)$ https://%{HTTP_HOST}/$1 [R=301,L]

In your https vHost:

RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^secure-form1\.html$
RewriteCond $1 !^secure-form2\.shtm$
RewriteCond $1 !^secure-form3\.php$
RewriteCond $1 !^secure-form4\.shtml$
RewriteCond $1 !^secure-form5\.cfm$
RewriteRule ^/(.+)$ http://%{HTTP_HOST}/$1 [R=301,L]

Note that if these two VirtualHost containers are set up properly, you really shouldn't need to check SERVER_PORT, since it'll be part of the vHost definition itself.

Jim

DepecheModem

6:47 am on Nov 20, 2009 (gmt 0)

10+ Year Member



Thanks Jim,
Unfortunately, they are not setup as virtual hosts. It is a single listener configuration with the SSL being handled by a BigIP load balancer. Dang, I just answered my own question as to why I've been getting those redirect loops -- the Apache server is not seeing the HTTPS requests -- it is being re-written by the BigIP before it gets to the listener. Hmmm... time for BigIP rules... Thanks for your help!

-Jay