https to http mod rewrite

Posted on 2009-12-23
Last Modified: 2013-11-21
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?
Question by:Dzynit
    LVL 15

    Expert Comment

    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. :)
    LVL 2

    Expert Comment

    .htaccess method:

    RewriteEngine On
    RewriteCond %{SERVER_PORT} 443
    RewriteRule ^(.*)$$1 [R,L]
    LVL 26

    Expert Comment

    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.
    LVL 14

    Author Comment

    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.)
    LVL 2

    Accepted Solution

    RewriteEngine On
    RewriteCond %{SERVER_PORT} 443
    RewriteCond %{REQUEST_URI} !^/ssl_dir
    RewriteRule ^(.*)$$1 [R,L]

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
    If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now