Search code examples
.htaccessmod-rewrite

Remove https (ssl) from certain url only


I want to remove secure http only for a certain url:

https://www.example.com/car-sharing.html

supposed to redirect to

http://www.example.com/car-sharing.html

I tried several .htaccess directives, for example

RewriteCond %{HTTPS} on
RewriteCond $1 ^(car-sharing\.html)
RewriteRule (.*) http://%{HTTP_HOST}%$1 [R=301,L]

or

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} car-sharing.html
RewriteRule ^(.*)$ http://www.example.com/%{REQUEST_URI} [R=301,L]

but I can't get it to work, the redirect from https to http never happens. Any help is much appreciated.


Solution

  • %{REQUEST_URI} includes the leading slash, so this should work:

    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} ^/car-sharing.html
    RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L,QSA]