Jump to content

[SOLVED] Rewriting to HTTPS for one page and HTTP for all other pages


mjurmann

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.