mjurmann Posted December 17, 2008 Share Posted December 17, 2008 Hello. We have a single page that needs to be rewritten to https, and the rest of the pages need to be http. So, if someone visits the https page and clicks on another link, the link will automatically be https. mod_rewrite needs to be able to accomplish two things: 1) Rewrite the secure.php page to https 2) If the website is in https, then the other pages needs to be rewritten to http. Here is what I've got so far. # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{HTTP_REFERER} (pay-invoice)$ [NC] RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301] Unfortunately, this is basically causing an infinite loop. Does anyone have any suggestions? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
mjurmann Posted December 21, 2008 Author Share Posted December 21, 2008 Can anyone help me with this? Quote Link to comment Share on other sites More sharing options...
mjurmann Posted December 21, 2008 Author Share Posted December 21, 2008 Alright, so this seems to be working, sort of: Options +FollowSymLinks RewriteEngine on # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_FILENAME} !dvd-order-form.php RewriteRule .* http://www.domain.com%{REQUEST_URI} [QSA,R=301,L] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443 RewriteCond %{REQUEST_FILENAME} dvd-order-form.php RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] # Redirect SSL Bots to SSL Robots.txt RewriteCond %{SERVER_PORT} ^443$ RewriteRule ^robots.txt$ robots_ssl.txt The only problem is that on the dvd-order-form.php page, the images within the images/ folder are pulling the http versions, rather than the https. This is causing the browser to display a warning prompt that there is both secure and insecure data. How can I redirect the images folder to pull the https versions of the images (only on the dvd-order-form.php page)? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
mjurmann Posted December 21, 2008 Author Share Posted December 21, 2008 Just in case someone cares: Options +FollowSymLinks RewriteEngine on # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443 RewriteCond %{REQUEST_FILENAME} dvd-order-form.php RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L,S=5] # Redirect all other pages to Non-SSL RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_FILENAME} !dvd-order-form.php ## Specify file types to ignore with rewrite RewriteCond %{REQUEST_URI} !(js|css) RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301] # Redirect SSL Bots to SSL Robots.txt RewriteCond %{SERVER_PORT} ^443$ RewriteRule ^robots.txt$ robots_ssl.txt Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.