skip to Main Content

I want to remove forceful https,and redirect https:// to http://

My .htaccess in the webroot folder is as follows:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTP:X-Forwarded-Proto} !https
 RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [L]
</IfModule>

I have tried

<IfModule mod_rewrite.c>
  #Redirect HTTPS to HTTP
   RewriteCond %{HTTP:X-Forwarded-Proto} =https
   RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

But it’s not getting redirected.

Thanks in advance

2

Answers


  1. i think you should force a http request from your AppController by changing it to something like this and check if it might help

    public function forceSSL() {
        return $this->redirect('http://' . env('SERVER_NAME') . $this->here); }
    
    public function beforeFilter() {
        $this->Security->blackHoleCallback = 'forceSSL';
        $this->Security->requireSecure(); }
    
    Login or Signup to reply.
  2. Make sure you have the following line in httpd.conf (mod_rewrite support-enabled by default):

    LoadModule rewrite_module modules/mod_rewrite.so
    

    Now you just need to edit or create a file .htaccess in the root directory of your domain and add these lines to redirect http to https:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
    

    Now that the visitor is typing http://www.yourdomain.com, the server automatically redirects HTTP to HTTPS https://www.yourdomain.com

    How to redirect HTTP to HTTPS on an Apache virtual host

    In addition, to force all web traffic to use HTTPS, you can also configure your virtual host file. There are two important points about virtual host configuration if SSL certificate is enabled.

    The first contains the configuration for non-secure port 80.

    The second is for secure port 443. To redirect HTTP to HTTPS for all pages of your website, first open the appropriate virtual host file. Then change it by adding the configuration below:

    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName www.yourdomain.com
    Redirect / https://www.yourdomain.com
    </VirtualHost>
    
    <VirtualHost _default_:443>
    ServerName www.yourdomain.com
    DocumentRoot /usr/local/apache2/htdocs
    SSLEngine On
    # etc...
    </VirtualHost>
    

    After all the changes, don’t forget to restart the server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search