1

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?

easymanstan
  • 25
  • 1
  • 1
  • 6

3 Answers3

4

You can't redirect https to http if you don't have ssl certificate or ssl isn't enabled on your server. You will get an ssl certificate error if you don't have the ssl certificate. You need to buy an ssl certificate for your domain in order to redirect https to http.

After getting a valid ssl certificate , you may use the following rule to redirect https://example.com/chat to http://example.com/chat

RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule ^chat http://example.com%{REQUEST_URI} [L,R=301]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
1

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]
Kuldeep Singh
  • 696
  • 10
  • 25
0

The following finally solved problem for me:

Redirecting all https and/OR www requests to non-https and non-www and all its subdirectories.

https://example.com/           to http://example.com/

https://www.example.com/  to http://example.com/

http://www.example.com/    to http://example.com/

added to my .htaccess file:

RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*) http://example.com/$1 [L,R=301]

Mind you, NOT escaping the "." with "\." in the RewriteCond

Worked on my shared hosting (escaping the "." with "\." did not work on my hosting, to my surprise)

Jürgen Fink
  • 3,162
  • 2
  • 23
  • 25