I like my website to be accessible by example.org
or https://example.org
not www.example.org
.
So I want http://www.example.org
to redirect to http://example.org
and http://www.example.org
to https://example.org
.
But an interesting thing happens:
https://www.example.org
redirects to https://example.org
but not http://www.example.org
to http://example.org
My main.conf:
<VirtualHost *:80>
ServerName example.org
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName example.org
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /pathtocert.pem
SSLCertificateKeyFile /pathtokey.pem
</VirtualHost>
<Directory "/var/www/html">
Options FollowSymlinks ExecCGI
AllowOverride None
Require all granted
</Directory>
My www.conf:
<VirtualHost *:80>
ServerName www.example.org
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html"
RedirectPermanent / http://example.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.org
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html"
RedirectPermanent / https://example.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /pathtocert.pem
SSLCertificateKeyFile /pathtokey.pem
</VirtualHost>
<Directory "/var/www/html">
Options FollowSymlinks ExecCGI
AllowOverride None
Require all granted
</Directory>
So what seems to be the problem? Also shouldn't both http
and https
redirects fail or succeed together?