https to http mod rewrite

What is the best or correct way to write the mod rewrite to grab any incoming page that starts with https and switch it to http?

(Previously the site was all https, but is no longer needed and they want it all switched back to http, but don't want to lose current traffic to 404's.)

Another thing with it though - there will be a single page required to be https. Will it cause looping or any problems if after the redirect rule is in place a normal 301 is added for only that one page?
LVL 14
Who is Participating?
citrateConnect With a Mentor Commented:
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/ssl_dir
RewriteRule ^(.*)$$1 [R,L]
hi Dzynit,

I had the Redirect directive added to the config section for SSL configuration (/etc/httpd/conf.d/ssl.conf)

I added the line at the end (just before the </VirtualHost>

  Redirect /

HTH, and happy new year. :)
.htaccess method:

RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$$1 [R,L]
If your going down the .htaccess route you'll want something along the following lines:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/page/that/must/be/ssl-ed [NC]
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/page/that/must/be/ssl-ed [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]

Note: You can do something very similar in you httpd.conf, by sticking the respective rules in the applicable Virtual host definitions.
DzynitAuthor Commented:
citrate's method worked easiest for 301 redirecting all the https to http, but when I try to add a redirect for the one page that still needs to be https it causes a loop.

arobert11 - using your code, the site stayed http of course, but the page that requires https just goes to the home page. And I don't think it was reporting that the old https links were 301.

Using citrate's code, I also added this after (but it causes a loop):
redirect 301 /my-ssl-page

Suggestions on getting that one page to stay https correctly?

(I'm terrible with htaccess and httpd.conf things so I really appreciate the help and advice.)
All Courses

From novice to tech pro — start learning today.