繁体   English   中英

htaccess和regex重定向多种样式

[英]htaccess and regex redirects for multiple styles

我想重定向以下所有内容

example.com
http://example.com
https://example.com
http://www.example.com

https://www.example.com

我有这个:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^/(.*):SSL$   https://%{SERVER_NAME}/$1 [R,L]


Options +FollowSymlinks
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule ^(.*)$ https://www.example.com/$1 [R=permanent,L]

下面的这两个正在工作,

http://www.example.com 
https://example.com 

但最后一个显示为:

https://www.example.com/https://example.com/

我该如何纠正这个问题,以便所有三个都正确重定向到https://www.example.com

谢谢你的帮助。

您想要的所有内容都可以在一个规则中完成,如下所示:

RewriteEngine on

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,NE,R=301]

确保这是根.htaccess中的第一条规则。

^(?:.*?:)?(?:\/\/)?(?:.*?\.)?(.*?\.)(.*)$

试试这个。

https://www.$1$2

参见演示。

http://regex101.com/r/lU7jH1/6

暂无
暂无

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

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