Apache HTTP请求301将服务不同内容的重定向到HTTPS,无重定向

Apache HTTP请求301将服务不同内容的重定向到HTTPS,无重定向,apache,.htaccess,url,mod-rewrite,redirect,Apache,.htaccess,Url,Mod Rewrite,Redirect,使用.htaccess我最近使用以下代码将我的所有网站http://请求重定向到https://上: RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^www\. RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 301重定向正在工作,现在每个人

使用.htaccess我最近使用以下代码将我的所有网站http://请求重定向到https://上:

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
301重定向正在工作,现在每个人都登录到https。但是,当用户使用一个书签链接http://或我向他们发送一个格式为http://而不是https://的Url时,他们会在一个不同的Url上登录,而不是单击网站上的链接

如果主页上有链接,URL如下所示:

如果使用http()将链接发送给客户,并且客户单击该链接,则该链接将加载:

我尝试使用.htaccess和以下代码从URL字符串中删除index.php?/,但效果不佳:

RewriteBase / 
RewriteCond %{THE_REQUEST} ^GET.*index\.php\?/ [NC] 
RewriteRule (.*?)index\.php\?/ / [R=301,NE,L] 
任何阻止人们使用index.php登录URL的建议都会令人惊讶

根据要求,这是整个htaccess文件: 重新启动发动机

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

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?/$1 [L]

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

RewriteBase / 
RewriteCond %{THE_REQUEST} ^GET.*index\.php\?/ [NC] 
RewriteRule (.*?)index\.php\?/ / [R=301,NE,L] 
按以下顺序排列:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?/$1 [L]

在测试之前,请确保清除浏览器缓存。

在上面的questionRewriteRule^(.*)$/index.php中添加?/$1[L]第二种情况是RewriteCond%{HTTP_HOST}^www\。不需要,您已经将所有非www.请求发送到https://www。这只是一条评论,不是答案。我的意思是最后一个,所以第一个重写cond%{HTTP_HOST}^www\。已经将用户发送到https和www,因此,在这之后,您需要做的唯一一件事是确保http://www.yoursite.com被发送到https://www.yoursite.com并立即执行测试