简体   繁体   English

将wordpress重定向到HTTPS

[英]Redirecting wordpress to HTTPS

I have a .htaccess file generated by a plugin. 我有一个由插件生成的.htaccess文件。 It looks like this: 看起来像这样:

# BEGIN Far Future Expiration Plugin
<IfModule mod_expires.c>
ExpiresActive on
<FilesMatch "\.(gif|jpeg|jpg|png)$">
ExpiresDefault "access plus 168 hours"
</FilesMatch>
</IfModule>
# END Far Future Expiration Plugin

# 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>

# END WordPress

I need to implement a HTTPS redirection. 我需要实现HTTPS重定向。 I've tried adding the following to the file but it gives me a Too many redirects error. 我尝试将以下内容添加到文件中,但它给了我太多重定向错误。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]

Any tips? 有小费吗?

This code will redirect any non https request to the same page/domain with https . 此代码会重定向任何非https请求发送至同一页/域https

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Note: some but not all ssl certificates don't include the www or non www domain depending on how you purchased it. 注意:根据您的购买方式,某些(但不是全部) ssl证书不包含www或非www域。 Due to this you may get an error and in addition to the code above you can use what you were attempting above. 因此,您可能会得到一个错误,除了上面的代码之外,您还可以使用上面的尝试。

RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]

This example will redirect non www sites to www , switch it around if you need the other case. 此示例会将非www网站重定向到www ,如果需要其他情况,请切换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM