Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect HTTPS to HTTP permanently, from Apache VirtualHost

There are many questions about redirecting HTTP to HTTPS like this:

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://www.example.com/ 
</VirtualHost>

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost>

but I need to do the other way around, from HTTPS to HTTP, possibly by not using mod_rewrite. Is that possible?

Apache Version: Server version: Apache/2.4.7 (Ubuntu)

I tried this but it doesn't work:

<VirtualHost _default_:443>
        ServerName example.com
        ServerAlias *.example.com
        Redirect "/" "http://example.com/"
</VirtualHost>
like image 403
somonek Avatar asked May 11 '16 07:05

somonek


People also ask

How do I automatically redirect http to HTTPS on Apache server?

In Apache, the preferred way to redirect HTTP to HTTPS is to configure the 301 redirect in the domain's virtual host.


1 Answers

Here is code that work for me.

<VirtualHost *:80>
    ServerName example.com  
    ServerAlias www.example.com 
    DocumentRoot /var/www/html/example.com
</VirtualHost>

<VirtualHost *:443> ServerName example.com RewriteEngine on RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] </VirtualHost>

like image 118
Kirit Patel Avatar answered Oct 07 '22 01:10

Kirit Patel