Hi all,
Last week I was working on a way to automatically redirect certain pages in my Web site to HTTPS while directing all other pages (not needing security) back to HTTP.
I was able to do this successfully with the help I received
in this forum thread.
Yesterday, I was told by a prospective client that when they visited our "sign-up" form using Google's Chrome Web browser, they are getting a completely blank page. Sure enough, I tested this with the latest version of Chrome on OSX and Windows 7 and got a blank signup page. It works great in Safari, Firefox, and IE, just not Chrome. Further research into how Chrome handles SSL security shows that is is even more strict than IE, and simply won't display mixed content at all.
Looking at the Chrome debug console showed that the signup.php script was trying to load insecure and secure content. It listed all of my style sheets, Javascript, etc. as insecure. This really confused me since all of those files are relative links in the <head> of the Web page and should be loaded using the same protocol of the base file????
I finally tracked down the issue by commenting out all of the ReWrite rules I had added to Apache, and then visiting the page in Chrome again using HTTPS... Lo and behold and it worked fine. This got me thinking...
It appears that due to my set of rewrite rules in my httpd.conf file:
PHP Code:
<Directory "/Library/WebServer/Documents/mysite">
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule !^(signup|signup_process|signup_conf|setup_co_and_user).php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]
</Directory>
<Directory "/Library/WebServer/Documents/mysite">
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(signup|signup_process|signup_conf|setup_co_and_user).php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
</Directory>
... any of the include files or <link> files were being rewritten by mod_rewrite to insecure HTTP even though the RewriteRule above tells apache NOT to rewrite my signup files. Included files of an ignored file must be treated differently. So the rewrite rules are apparently not only working on the base file in the directory, but also on any other included file that that file refers to - even if that file was a relative link or include file...
This seems awfully strange? Can anyone verify that the mod_rewrite rules not only apply to the base file but to any file that base file refers to at the time it is requested by the browser.
The whole reason to do this in the first place was to (1) ensure I can use relative links throughout my site and (2) ensure that certain scripts are always secured, even if the user tries to change the protocol back to HTTP.
The solution seems to be the following:
(*) Tell mod_rewrite to NOT rewrite the include files back to HTTP such as my CSS and Javascript include files called in my secure programs. Can this be done?
Maybe there a way to tell mod_rewrite to not traverse all the subdirectories of the directory I specify when it applies its rules? Basically I only want mod_rewrite to look at the files in my root "/Library/Webserver/Documents/mysite" and not all of the subdirectories under /mysite/ such as "/images" , "/includes" , and "/css". This just seems to be getting messy now.
The normal hypertext protocol handler would make any of my relative linked include files secure when the base file is loaded securely, so I really don't want all of my support files to be subject to redirects with mod_rewrite. I sure hope this is possible.
Thanks for the help.