重定向.htaccess到ssl不工作


Redirect .htaccess to ssl is not working

我正在尝试将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永久链接设置中有反映https://xyz.com/homesite URL

请将以下代码添加到您的.htaccess文件中,以将整个网站重定向到https。

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

若要重定向所选页面,请按如下方式重写规则。

RewriteRule ^page1(.*) https://%{SERVER_NAME}/page1$1 [R,L]

如果你喜欢插件,你可以使用这个插件:https://wordpress.org/plugins/https-redirection/.

试试这个,它对我有效

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.xyz.com/$1 [R,L]

请将此代码添加到.htaccess文件中,并让我知道一些事情。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

这段代码在我的网站上运行良好,还请检查您的托管提供商是否有SSL证书。

检查此链接http://kuldipmakdiya.wordpress.com/2014/10/14/redirect-htaccess-to-ssl-is-not-working/