KOMPX.COM or COMPMISCELLANEA.COM   

HTTPS to HTTP redirect for a single page

Redirecting a single page with HTTPS to the page with HTTP. Server configuration: Apache + nginx. SSL is enabled for the whole web site, so all pages are served with HTTPS. But there is a need to make just one single page to be with HTTP. Directives for .htaccess file:


RewriteEngine On
RewriteCond %{HTTP:HTTPS} on [NV]
RewriteRule ^(page\.html)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

Commentary

Enable runtime rewriting engine:


RewriteEngine On

If HTTPS is present:


RewriteCond %{HTTP:HTTPS} on [NV]

Then, when a page name and extension correspond to the search group in parentheses, form for it a URI with HTTP:


RewriteRule ^(page\.html)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

Notes

  1. RewriteCond %{HTTP:HTTPS} on [NV] is not the only way to detect if HTTPS is present. Moreover, for some server configurations other directives may be more suitable, like RewriteCond %{SERVER_PORT} 443, for example. The point is to find out somehow if HTTPS is on. So it should probably be checked by practice what is going to work in a particular case.
  2. QSA is used to keep the existing query string, if there is any, when the replacement URI also contains a query string. So that in the end both query strings are to be combined. More on the subject: http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_qsa
Web servers
More