php - 将 .htaccess 重定向到 ssl 不起作用

标签 php wordpress .htaccess redirect ssl

我正在尝试将 xyz.com 重定向到 https://xyz.com

我的代码

# BEGIN WordPress
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^(.*)$ https://xyz.com/$1 [R=301]

RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
RewriteRule ^(.*/)?sitemap.xml wp-content/sitemap.php [L]

# END WordPress

我也试试下面的代码

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

它显示了这个错误 页面没有正确重定向

实际上它是一个 WordPress 网站。

如何解决这个问题?

提前致谢

最佳答案

你的规则是这样的:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://xyz.com%{REQUEST_URI} [R=301,L]

还要确保在你的 WP 永久链接设置中你有 homesite URL 反射(reflect) https://xyz.com/

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

相关文章:

php - 如何在现有的网络项目上实现翻译?

php - 如何在 ZF2 中创建表单输入/元素

php - 为什么我不能在 nginx 中拥有自己的自定义根指令

css - Wordpress 中心移动导航

wordpress - woocommerce_order_status_changed 钩子(Hook) : getting old and new status?

facebook - 自动时间线 Action 发布

php - 嘻哈 PHP 下载?

php - mod_rewrite 不适用于 jQuery.ajax

.htaccess - Joomla 网站 .htaccess 不断被黑

.htaccess - htaccess 或 php 301 重定向 url