NOTE: config and error updated to be clearer.
I have the following .htaccess for my site running apach 2.4 on Ubuntu:
<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} ^(www\.)example1.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)example2.com
RewriteRule ^(.*)$ https://www.example2.com/$1 [L,R=301]
</IfModule>
If I go to http://example2.com , http://www.example2.com or
http://www.example1.com it redirects to
https`
if I go to http://example1.com
it stays as http.
Is there something I am missing so that it will redirect with just the base /
url?
The problem is these two rules:
RewriteCond %{HTTP_HOST} ^(www\.)example1.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)example2.com
You need to add ?
to make the www.
optional:
RewriteCond %{HTTP_HOST} ^(www\.)?example1.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example2.com
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.