Flyman
Flyman

Reputation: 3

Can't get rid of a persistent Apache2 redirect (even with purge/flush/reinstall)

I'm absolutely stumped here. I was attempting to forward all http requests to https (so port 80 to 443). I tired a few methods, including

Redirect / https:/address.com

Redirect permanent / https://address.com

RedirectRewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

It finally took after I tried Redirect permanent, but the forward only half worked (would redirect to proper host but wouldn't serve the page), but when I tried to undo the redirect, it persisted (so still leading to a broken address).

I tried overriding it, tried flushing DNS, completely purged apache2 and reinstalled, and still this redirect persists. I've run out of ideas. It's not just my browser cache either; I've tested on multiple external IP's with the same result.

The .conf with the broken redirect is as follows (Note no redirect is currently active), this conf is no longer active either.

<VirtualHost *:80>
    ServerName www.example.com

    ServerAdmin webmaster@localhost
    #DocumentRoot /var/www/html

    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    #Redirect / https:/address.com

    #Redirect permanent / https://address.com

    #RedirectRewriteEngine On
    #RewriteCond %{HTTPS} !on
    #RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The only virtual host that's active is the host that I actually want working, which is as follows:

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


<VirtualHost *:443>
    ServerName address.com
    ServerAlias www.address.com
    ServerAlias *.address.com

    ServerAdmin webadmin@localhost
    DocumentRoot /disk2/example_site

    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


    SSLEngine on
    SSLCertificateFile example.crt
    SSLCertificateKeyFile example.key
    SSLCACertificatePath /example/
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

And still, the redirect persists.

Upvotes: 0

Views: 1536

Answers (3)

sakuragasaki46
sakuragasaki46

Reputation: 31

Remove any reference to permanent redirect either in configuration or in web app, depending on where you did it.

Then, just clear your browser cache as a whole. If it doesn't work, clear browser data too.

It's a problem of client, not server. Never use 301 or 308 redirect if you are not sure of what you're doing, they'll be cached indefinitely.

Upvotes: 0

symcbean
symcbean

Reputation: 48367

Never use a permanent redirect.

As you've found removing it from your server does not remove the redirection for any browser which has visited the page. The instruction is always cached indefinitely by the browser.

The subsequent rewrite rules mean that you will be supplying an https response to an http request - which is clearly non-sensical.

Add [L,R] to the final line (not R=301 as suggested elsewhere on stack overflow). And if you really are doing away with non-ssl permanently and completely, use HSTS.

(BTW to fix the browsers you'll need to interfere with the cache database directly or delete and reinstall)

Upvotes: 2

BaZZiliO
BaZZiliO

Reputation: 232

//this should be a comment

this should helps you.

Redirect permanent / https://www.your_site_name_here.com/

I read, that you try this. Could you post whole apache config ?

Upvotes: 0

Related Questions