.htaccess 301 重定向无法正常工作。需要强制HTTPS
.htaccess 301 redirect not working correctly. Need to force HTTPS
我们想强制对我们网站的所有请求都使用 HTTPS 协议。我们只是想替换URL的协议,其余的URI可以保持不变。当我们从主页开始浏览网站时,一切正常。当我们首先打开不是主页的任何其他页面(即 ourdomain.com/this-is-a-page/)时,我们不会被重定向到使用 HTTPS。我需要对我的 htaccess 文件进行哪些更改才能完成此操作?
这有效(它插入 https):ourdomain.com
这不起作用:我们的域。com/this-is-a-page/
谢谢!
htaccess 代码:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
您需要将重定向规则 放在路由规则 之前。重写引擎循环,因此首先执行路由规则(将内容路由到 index.php
),重写引擎循环,然后应用第二个重定向规则,重定向 错误的东西 .尝试:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
我们想强制对我们网站的所有请求都使用 HTTPS 协议。我们只是想替换URL的协议,其余的URI可以保持不变。当我们从主页开始浏览网站时,一切正常。当我们首先打开不是主页的任何其他页面(即 ourdomain.com/this-is-a-page/)时,我们不会被重定向到使用 HTTPS。我需要对我的 htaccess 文件进行哪些更改才能完成此操作?
这有效(它插入 https):ourdomain.com
这不起作用:我们的域。com/this-is-a-page/
谢谢!
htaccess 代码:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
您需要将重定向规则 放在路由规则 之前。重写引擎循环,因此首先执行路由规则(将内容路由到 index.php
),重写引擎循环,然后应用第二个重定向规则,重定向 错误的东西 .尝试:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]