简体   繁体   中英

.htaccess http to https redirect for aliased domain

I am, into a scenario where two domains with multiple sub domains are hosted on one site only (files are in one directory but two domains pointing to it) ie

www.abc.com (is the main site) www.abc.ca (is the site that is aliased to the web space of the above site)

now i want to add a rule in .htaccess to redirect them from http:// to https:// which is not working as it causes a loop there or is not redirecting properly

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Need help to resolve this issue.

Apache Virtual Host is recommended solution for this nowadays, try this:

<VirtualHost *:80>
    ServerName example.org
    ServerAlias *.example.org
    Redirect / https://example.org/
</VirtualHost>

<VirtualHost *:443>
    ServerName example.org
    ServerAlias *.example.org

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM