1

After trying many different combinations to redirect my shopware6 installation on a server with apache2, I am not able to make the www to non-www redirection work.

Here's my conf file :

<VirtualHost *:80>
        ServerName vanparysbakery.emakers.be
        ServerAlias www.vanparysbakery.emakers.be
        RewriteCond %{HTTPS} off
        RewriteEngine On
        ServerSignature Off
</VirtualHost>
<VirtualHost *:443>
        Protocols h2 h2c http/1.1
        LoadModule ssl_module /usr/lib64/apache2-prefork/mod_ssl.so
        DocumentRoot /var/www/bakery/public
        ServerName vanparysbakery.emakers.be
        ServerAlias www.vanparysbakery.emakers.be
        <Directory /var/www/bakery/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>
        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite HIGH:!aNULL:!MD5:!ADH:!DH:!RC4
        SSLHonorCipherOrder on
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/vanparysbakery.emakers.be/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/vanparysbakery.emakers.be/privkey.pem
</VirtualHost>

Here are the different ways I tried to make the redirection (added this below "RewriteEngine on" in the conf file) :

RewriteCond %{HTTP_HOST} ^www.vanparysbakery.emakers.be [NC]
RewriteRule ^(.*)$ http://vanparysbakery.emakers.be/$1 [L,R=301]

&&&&

RewriteCond %{SERVER_NAME} =www.vanparysbakery.emakers.be [OR]
RewriteCond %{SERVER_NAME} =vanparysbakery.emakers.be
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Also tried this in the .htaccess file of my shopware folder :

RewriteEngine On
RewriteRule ^(.*) http://vanparysbakery.emakers.be/$1 [QSA,L,R=301]

&&&&

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

What am I doing wrong? I learned many things about this and all the solutions I found did not give the expected result. I suspect an apache configuration to "block" this redirection.

Any kind of help would be great :)

UPDATE (new content of my conf file as suggested by @MikeMoy) :

<VirtualHost *:80>
        ServerName vanparysbakery.emakers.be
        ServerAlias www.vanparysbakery.emakers.be
        RewriteEngine on
        #Redirect    301 /   http://vanparysbakery.emakers.be/
        RewriteCond %{HTTP_HOST} www.vanparysbakery.emakers.be [NC]
        RewriteRule ^/?(.) vanparysbakery.emakers.be/$1 [L,R,NE]
        ServerSignature Off
</VirtualHost>
<VirtualHost *:443>
        Protocols h2 h2c http/1.1
        LoadModule ssl_module /usr/lib64/apache2-prefork/mod_ssl.so
        DocumentRoot /var/www/bakery/public
        ServerName vanparysbakery.emakers.be
        ServerAlias www.vanparysbakery.emakers.be
        <Directory /var/www/bakery/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} www.vanparysbakery.emakers.be [NC]
        RewriteRule ^/?(.) https://vanparysbakery.emakers.be/$1 [L,R,NE]
        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite HIGH:!aNULL:!MD5:!ADH:!DH:!RC4
        SSLHonorCipherOrder on
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/vanparysbakery.emakers.be/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/vanparysbakery.emakers.be/privkey.pem
</VirtualHost>

UPDATE 2 : I tried the same fix for another website on which we have the same behaviour 'covarmed.emakers.be'. After what I am executing this command : curl -I www.covarmed.emakers.be (I also tried this with "covarmed.emakers.be" & "http://www.covarmed.emakers.be"). The response was everytime the same :

HTTP/1.1 302 Found
Date: Fri, 27 Aug 2021 09:42:09 GMT
Server: Apache/2.4.38 (Debian)
Location: https://covarmed.emakers.be//
Content-Type: text/html; charset=iso-8859-1

But in browsers, the result is still the same, the redirection is NOT working.CURL RESPONSE

Umar Zahid
  • 323
  • 1
  • 13

1 Answers1

2

something like this, then restart your server for new config to be loaded

<VirtualHost *:80>
        RewriteRule ^(.*)$ https://vanparysbakery.emakers.be/$1 [R,L]
</VirtualHost>


<VirtualHost *:443>
        RewriteCond %{HTTP_HOST} www.vanparysbakery.emakers.be [NC]
        RewriteRule ^/?(.*) https://vanparysbakery.emakers.be/$1 [L,R,NE]
 </VirtualHost>
mister_cool_beans
  • 1,441
  • 1
  • 8
  • 19
  • Ok with this test, it's indeed working but with any of my browser, it's not redirecting... Can you try on your browser maybe? The URL stays as : https://www.vanparysbakery.emakers.be/ and the "https" part is crossed out and the page says "Your connection is not private" (classic text for a HTTPS not working site) – Umar Zahid Aug 24 '21 at 15:11
  • If I a : curl -I www.vanparysbakery.emakers.be, I also receive a redirected response : HTTP/1.1 301 Moved Permanently Date: Tue, 24 Aug 2021 15:00:34 GMT Server: Apache/2.4.38 (Debian) Location: https://vanparysbakery.emakers.be/ Content-Type: text/html; charset=iso-8859-1 – Umar Zahid Aug 24 '21 at 15:17
  • I updated my question with the whole content of my "updated" conf file with the code you sent before. and it's still acting the same way when browsing the site.. Not redirecting when I add "www" before neither in http nor in https. – Umar Zahid Aug 25 '21 at 08:43
  • Yes it is enabled. – Umar Zahid Aug 25 '21 at 08:47
  • Yeah like 1000 times – Umar Zahid Aug 25 '21 at 08:57
  • you mean a2ensite vanparysbakery.emakers.be? Yeah of course, without doing this, it's even not possible to access the site – Umar Zahid Aug 25 '21 at 10:23
  • YEah if I change to 444, even without the www, the site cannot access with https. So it's using the correct file – Umar Zahid Aug 25 '21 at 13:14
  • Yes, I tried on Chrome, Firefox & Edge. Can you for a test perspective check on your side? And unfortunately, nothing is added in the access logs when I browse on any of the sites on the server. – Umar Zahid Aug 26 '21 at 07:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236431/discussion-between-umar-zahid-and-mikemoy). – Umar Zahid Aug 26 '21 at 07:24