Raphael Portmann Raphael Portmann -4 years ago 96
PHP Question

Forcing Non-SSL when specific url parameter is given

Ok I found out that I can force users to use SSL by changing something in the .htaccess file:

RewriteEngine On
RewriteBase /

# Force SSL
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Deny Access to all .htaccess
<Files .htaccess>
order allow,deny
deny from all

I'm not really good in writing .htaccess files so i most likely copy-paste it from the internet.

My question is if it's possible to always force ssl with one exception (When someone is visiting a http site with a specific url parameter).

Example 1:


gets redirected to


Example 2:


doesn't get redirected to


Is it possible to write that in htaccess or do i need to include a php file to every single page that's doing this?

Answer Source

This question is a DUPLICATE


Put this before the # Force SSL condition.

RewriteCond %{QUERY_STRING} (^|&)nossl=(1)(&|$)
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download