Wordpress 使用.htaccess从http重定向到https
我想将我的wordpress网站从http重定向到https,所以我在Wordpress 使用.htaccess从http重定向到https,wordpress,.htaccess,redirect,Wordpress,.htaccess,Redirect,我想将我的wordpress网站从http重定向到https,所以我在.htaccess中使用下面的代码。但它给我的错误是“页面没有正确重定向” RewriteCond %{HTTPS} off RewriteRule ^ https://www.mywebsite.com%{REQUEST_URI} [L,NE,R=301] 我已经在wp config文件中启用了SSL,如果我从一个页面转到另一个页面,它可以正常工作。只有当我在浏览器中复制粘贴任何http链接时,我才遇到问题,然后它不会重定
.htaccess
中使用下面的代码。但它给我的错误是“页面没有正确重定向”
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.mywebsite.com%{REQUEST_URI} [L,NE,R=301]
我已经在
wp config
文件中启用了SSL,如果我从一个页面转到另一个页面,它可以正常工作。只有当我在浏览器中复制粘贴任何http
链接时,我才遇到问题,然后它不会重定向到https
,我使用以下命令,还确保您没有可能启用的缓存插件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]]
</IfModule>
重新启动发动机
重写基/
重写cond%{HTTPS}=在…上
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]]
#开始WordPress
重新启动发动机
重写基/
重写cond%{HTTPS}=在…上
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
接下来要注意的是,确认WordPress地址和站点地址中有
https
。下一点,如果页面中只有http
,那么它有时也会显示错误,因此请确认每个http
都已更新为https
,将http重定向到https:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写cond%{HTTPS}=在…上
重写规则^(.*)https://%{SERVER_NAME}/$1[R,L]
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
在禁用缓存的Chrome开发工具中测试,并在“网络”选项卡中签入301/302重定向URL。@anubhava ERR\u to\u MANY\u重定向No,Chrome开发工具会显示在ERR\u to\u MANY\u重定向之前的每个重定向。
error.ERR\u to\u MANY\u重定向您是否更新了数据库中的站点URL以包含https?听起来WordPress正试图将https重定向回http?因此重定向循环。Wordpress地址已经是https了,如果我从一页转到另一页,它可以正常工作。但现在的问题是,若我调用http
url,它就不会重定向到https
。我试过你的代码,但还是一样的错误。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress