我正在尝试将 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 永久链接设置中你有 home
和 site
URL 反射(reflect) https://xyz.com/
关于php - 将 .htaccess 重定向到 ssl 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26230425/