我正在尝试将我的 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/