I know many people have ask similar not to say the same question before:
How can I redirect http to https (Using Apache)?/Why does it not do so?
There is even a "code" snippet on the Wikipedia page of HTTP 301 status code that redirects to https.
But after hours of searching I tried many different methods out of with only one is working:
<meta http-equiv="refresh" content="https://example.org">
as a default page at /var/www/html/index.html
Even though it successfully redirects it is more than ugly and also not really liked by search engines and increases loading time.
To get us all on one level this is my Apache configuration. I also use Django in combination with Apache in case that has any relevance.
So here is a listing of all my attempts:
Use another VirtualHost
<VirtualHost *:80> Redirect permanent / https://example.org/ </VirtualHost>
Use a rewrite that redirect everything that not connects on port 443 to the corresponding https page:
RewriteEngine On RewriteCond %{SERVER_PORT} !443 RewriteRule ^(/(.*))?$ https://%{HTTP_HOST}/$1 [R=301,L]`
Use the implementation mentioned from Wikipedia:
RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.org/$1 [R,L]
I tried these options (where it made sense) in both apache2.conf
and .htaccess
files. Obviously with no success. Weirdly enough when I visit example.org and then after it has loaded manually type example.org/# the last two methods worked. I have tried also with only example.org/ and the same procedure but without #. But that does not work.
What other options are there (for a 301-Redirect)? Why does this not work? And if it possible: How can I modify it to get it working?