0

Using other Stack Overflow help questions I have tried to setup a way to redirect https and www. to my https:example.com site. I have the https redirect working but it isn't going from https://www.example.com to https://example.com.

http:www.example.com -> https:example.com   ----works
http:example.com -> https:example.com   ----works
https:example.com -> https:example.com   ----works
https:www.example.com -> https:example.com   ---- Doesnt work

Here is my config file

<VirtualHost *:80>

ServerName example.com
ServerAdmin example@gmail.com

DocumentRoot /var/www/html/example/public

<Directory /var/www/html/example>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

Redirect / https://example.com/

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

</VirtualHost>

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

What am I doing wrong?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Chris Grim
  • 149
  • 1
  • 6
  • 20
  • you have to use htaccess for this fearture to work properly, check htacess redirect www and https – Nikos M. May 28 '20 at 18:12
  • What about this post though? https://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www – Chris Grim May 28 '20 at 18:34
  • Having a different virtual host is one solution, but to achieve all as simply as possible using htaccess rewrite and a server alias in virtual host (eg the alias can be the www.example.com, while the name is example.com) might be the best way. (Personaly have used this solution in more than one occasion). htaccess rewrite is not heavy as the post implies and is very flexible – Nikos M. May 29 '20 at 14:30

0 Answers0