Hi, I need help with redirecting HTTP to HTTPS. I have been trying a number of different solutions from various forums but I can’t seem to get any to work and I am not sure what I am missing or forgetting to do.
Redirecting to HTTPS on computer is working fine, but I think most modern browsers attempt to redirect to HTTPS by default now anyway. The problem is on mobile, if I type in my domain without specifying HTTPS mobile browsers will just try to access the site on HTTP by default and I think the connection just times out as it produces a blank white page.
When I use whynopadlock.com the Force HTTPS status returns “Your webserver is not forcing the use of SSL.”
I have included what I hope are the nessesary files below. My VirtualHost *:80 has some of the different rewrites and redirects that I can remember trying in comments at the bottom. I also have rewrite enabled and have been restarting Apache with each change and testing against whynopadlock.
My domain is: www.unchartedpixels.co.uk
My web server is: Apache/2.4.25 (Raspbian)
The operating system my web server runs on is: Raspbian 9 (stretch)
I can login to a root shell on my machine: yes
Edit - Not sure what is happening with the code layout, will try to fix it
I have removed the comments to help reduce clutter.
000-default-le-ssl.conf
< IfModule mod_ssl.c>
< VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/unchartedpixels.co.uk/public_html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName unchartedpixels.co.uk
ServerAlias www.unchartedpixels.co.uk
SSLCertificateFile /etc/letsencrypt/live/unchartedpixels.co.uk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/unchartedpixels.co.uk/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</ VirtualHost>
</ IfModule>
unchartedpixels.co.uk.conf
< VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName unchartedpixels.co.uk
ServerAlias www.unchartedpixels.co.uk
DocumentRoot /var/www/unchartedpixels.co.uk/public_html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =www.unchartedpixels.co.uk [OR]
#RewriteCond %{SERVER_NAME} =unchartedpixels.co.uk
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
#Redirect permanent / https://www.unchartedpixels.co.uk/
RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{HTTP_HOST} unchartedpixels\.co\.uk [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.unchartedpixels.co.uk/$1 [R,L]
</ VirtualHost>
Apache2.conf
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
ServerName localhost