0

I am trying to redirect the www domains to the non-www domains, as the www domains do not have a SSL Certificate, but the non-www's do. I have looked at the following questions

Generic htaccess redirect www to non-www

htaccess redirect from www to non-www

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

However the code provided (above) in the answers don't work wherever I put it. I am fairly inexperienced in htaccess so I don't know how to solve it.

The following is my current htaccess.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?sitename.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?sitename.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?sitename.de$ 
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www.)?sitename.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?sitename.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?sitename.de$
RewriteRule ^(/)?$ wp/index.php [L]
</IfModule>

Note: The above htaccess is working properly and redirecting accordingly in Google Chrome. However, Safari and Firefox output the following when addressing the www domain:

Firefox output

Eugène Adell
  • 3,089
  • 2
  • 18
  • 34
Rubenxfd
  • 434
  • 1
  • 5
  • 19
  • browsers check SSL before to contact the server then to remove this warning you have to change the SSL configuration. what is the warning about ? it's because the www domain use the SSL certificat for the non-www domain ? – Kaperto Dec 11 '19 at 13:56
  • The warning is indeed for the SSL not being present on the www domains. The certificates are only for the non-www domains. However as I understand it should be possible to redirect a non-safe url to a safe-url, am I right? – Rubenxfd Dec 11 '19 at 13:58
  • this warning is expected because you are leaving a "secure" https domain for a "non-secure" http (in the first block of conf you are giving). If it is ok for you to keep the https , we can give you the good `RewriteRule`. – Eugène Adell Dec 11 '19 at 19:57

0 Answers0