php - wordpress http 到 https 重定向不起作用

标签 php wordpress .htaccess ssl https

我正在尝试将我的 wordpress 网站从 http 重定向到 https。我的 wordpress 网站在 EC2 实例上,我点击此链接寻找 link for redirection

我能够看到 https 正常工作,但是没有发生从 http 到 https 的默认重定向。就像我去 http://testwordpress.com它应该被重定向到 https://testwordpress.com

我遵循了大部分答案 from this link , 但似乎没有什么对我有用

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://testwordpress.com/$1 [R,L]
</IfModule>

# END WordPress

下面的代码给我 503 错误代码

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTPS_HOST} !^testwordpress.com$ [NC]
RewriteRule ^(.*)$ https://testwordpress.com/$1 [L,R=301]

最佳答案

要使用 .htaccess 强制 HTTPs,您需要使用的是:

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

将它放在 .htaccess 文件的顶部,并确保在测试它之前清除缓存。

关于php - wordpress http 到 https 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45837542/

相关文章:

php - 我如何最好地使用 php 删除 XHTML 认为无效的 unicode 字符?

php - 从匿名函数中中断 array_walk

java - 如何通过 Selenium 关闭对话框?

php - Uncaught Error : Class 'WP_Query' not found in url - Wordpress

apache - 引用:mod_rewrite,URL重写和“漂亮链接”说明

php - 使用 php Imagemagick 调整图像大小

带范围过滤器的 PHP 搜索查询

html - 如何让导航居中?

php - 不同域可用的cookies/htaccess转发

php - 使用 .htaccess 为子域强制使用 SSL HTTPS