Search code examples
apache.htaccesshttp-redirectmod-rewrite

Redirect https to http on non-https server using htaccess


My server isn't set up for HTTPS, however some users are still browsing using HTTPS in the URL. This is preventing my chat application from working properly.

I need to redirect the chat pages from HTTPS to HTTP by changing the htaccess file. The pages have the URLs /chat, /chat/index and chat/text.

I've tried the following but can't seem to get it to work:

RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule ^chat$ http://%{HTTP_HOST}/$1 [R=301,L,NC]
RewriteRule ^chat/index$ http://%{HTTP_HOST}/$1 [R=301,L,NC]
RewriteRule ^chat/text$ http://%{HTTP_HOST}/$1 [R=301,L,NC]

What am I doing wrong?


Solution

  • If you don't have HTTPS on your server then don't be selective, redirect everything to HTTP

    # Redirect HTTPS to HTTP
    RewriteEngine On
    RewriteCond %{HTTPS} on
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]