我正在尝试将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
反映https://xyz.com/
的URL关于php - 将.htaccess重定向到ssl无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26230425/