简体   繁体   English

如何使用.htaccess将所有http流量重定向到https和www.domain.com

[英]how to use .htaccess to redirect all http traffic to https AND www.domain.com

I've tried several solutions posted here, none of them seem to work - I just get redirect errors. 我已经尝试过这里发布的几种解决方案,但它们似乎都不起作用-我只是遇到重定向错误。

What I am trying to do is redirect all traffic to https for: 我想做的是将所有流量重定向到https:

http://domain.com
http://www.domain.com
https://domain.com
http://alias.com
http://www.alias.com
https://alias.com

should all go to: https: // www.domain.com 应该都去:https://www.domain.com

currently addresses starting like: http: // www won't redirect to https. 当前地址开头为:http:// www将不会重定向到https。

here is the htaccess file 这是htaccess文件

RewriteEngine On
RewriteBase /

# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L] 

# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]

# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]

You should get rid of the www redirects at the bottom: 您应该摆脱底部的www重定向:

RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]

Don't need them, you just need a single redirect at the top, replace: 不需要它们,您只需要在顶部进行单个重定向,然后替换:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L] 

with

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]

This should take care of all the redirects. 这应该照顾所有重定向。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用.htaccess将http://www.domain.com重定向到https://www.domain.com - Redirect http://www.domain.com to https://www.domain.com using .htaccess 通过htaccess将所有流量重定向到https://www.domain.com - redirect all trafic to https://www.domain.com via htaccess 如何使用.htaccess通过HTTP和HTTPS将传入请求从domain.com重定向到www.domain.com? - How do I redirect incoming requests from domain.com to www.domain.com via HTTP and HTTPS using .htaccess? SSL错误:如何通过.htaccess将https://www.domain.com重定向到http://domain.com以避免SSL错误 - SSL Error: how to redirect https://www.domain.com to http://domain.com via .htaccess to avoid SSL error 将http://www.domain.com重定向到https://domain.com - redirect http://www.domain.com to https://domain.com 如何将domain.com或www.domain.com重定向到https www.domain.com - How to redirect domain.com or www.domain.com to https www.domain.com 如何将http://domain.com重定向到https://www.domain.com? - How to redirect http://domain.com to https://www.domain.com? htaccess如何将www.domain.com和domain.com都重定向到www.realdomain.com - htaccess how to redirect both www.domain.com AND domain.com to www.realdomain.com .htaccess-将domain.com和www.domain.com重定向到www.domain.com/en - .htaccess - redirect domain.com and www.domain.com - to www.domain.com/en http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess - http to https AND //domain.com to www.domain.com AND subdomain.domain.com to subdomain.domain.com through htaccess
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM