Reputation: 120
i have a 301 redirect from all domains to https://example.de. The redirect works with http://www.example, www.example with all tld (.com,.eu.net). But with https://www.example it doesnt redirect to https without the www. Here is the Mod rewrite:
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} ^www\.example\.de$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.de$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.at$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.at$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.eu$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.eu$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.net$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.org$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]
Edit: The following works so far
RewriteCond %{HTTPS} on [NC]
RewriteCond %{HTTP_HOST} !^example\.de$ [NC]
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteBase /
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]
Upvotes: 0
Views: 311
Reputation: 41209
Your rule doesn't redirect https
urls because you are not using correct Rewrite Conditions. Also you dont need to write multiple conditions to test a domain name. Instead of using two RewriteCond
lines to test www.example.com
and example.com
you can do it in a single condition something like. RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
.
The following is the shorter version of your rules.
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.at$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.eu$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.org$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.net$ [OR]
# the main domain. redirect www.example.de to example.de
RewriteCond %{HTTP_HOST} ^www\.example\.at$
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]
Clear your browser cache before testing this change.
Upvotes: 1