.htaccess htaccess非www访问www,而http访问https和http://www 到https://www
基本上,我想要这些.htaccess htaccess非www访问www,而http访问https和http://www 到https://www,.htaccess,.htaccess,基本上,我想要这些 非www到www http到https 到 我目前的访问权限是这个 Options -Indexes Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php?url=$1 [QSA,NC,L] RewriteCond %{
- 非www到www
- http到https
- 到
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?url=$1 [QSA,NC,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1
这样可以很好地工作,但是当您手动转到http://domain.com
,并将其更改为https://domain.com
,它添加了两组index.php
有什么想法吗?我发现您的代码有一个问题,就是您在
WWW
上有$1
和HTTPS
重定向,这将在末尾添加两次请求URI路径,因为您已经有%{request\u URI}
:
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}:443%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?url=$1 [QSA,NC,L]
另外,如果您首先将HTTP
重定向到HTTPS
(如果需要),然后检查WWWW
是否缺少重定向(如果需要,再次)
可能会在没有[R=301,L]
的情况下保留HTTPS
规则,但如果URL已经正确,我们希望避免处理更多规则
请记住,规则的顺序非常重要。我很困惑。如果http转到https,而非www转到www,则
http://domain.com
应转到https://www.domain.com
对吗?https和www都适用。这正是我的观点,使用我目前的htaccess是不会发生的。嗯,有一部分。如果您手动编辑url,它会添加两组index.php。确定如此接近。当url为https://www并且您手动从中删除www时,它返回https://www,但不添加index.php,这很好。但是现在,如果url是https,并且您手动从中删除S,那么它将返回http,而不带S。。我真的很感谢你帮我修好了它。这正是我想要完成的。非常感谢。