2015-10-07 114 views
2

我刚刚购买了SSL证书的WordPress站点,并希望人们去https://www ......而不是http://www ..如何在Wordpress中重定向到https?

我读过你需要改改的WordPress地址(URL)和设置 - 常规中的仪表板中的站点地址(URL)。

我也看了,你需要使用.htaccess文件中的重定向补充:

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

我需要做两件事?

如果是的话,上面的代码是否被放置在默认的Wordpress .htaccess代码中,还是会出现在它上面?

感谢

+0

更换的http://www.example.com所有实例重命名数据库中的所有图像(大多数人从一个域转移时,WP站点到另一个站点使用它)如果您将您的整个网站转换为SSL,您可以使用“WP Force SSL”插件。然后使用https或任何其他静态的地方更新CSS上的所有图像路径。 https://wordpress.org/plugins/wp-force-ssl/ – galfaro

回答

1

我对.htaccess规则并没有太多用处,但我知道这不是我使用的规则。在不断变化的WordPress的地址和网站地址(如你所指出的)一起,我更改默认的WordPress的.htaccess到

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{SERVER_PORT} !^443$ 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

但是,如果这是你要运行到您的数据库没有问题的现有站点充满了使用http协议的图像链接的内容,这将在浏览器中打破你的挂锁。我没有编辑所有的帖子,而是使用这个工具。

https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

,只是用https://www.example.com

+0

谢谢。在上面的.htaccess规则中,我需要添加完整的域名还是仅使用上述规则? 对不起,只是一个新手。 – user3766656

+0

嗨,抱歉,延迟回复。只需按照原样使用它,不需要将域放入任何位置。 :) – McNab

0

您可以functions.php

function redirectToHTTPS(){ 
if($_SERVER['HTTPS']!="on"){ 
    $redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
    header("Location:$redirect"); 
}} 
add_action('init','redirectToHTTPS'); 

您还可以使用里面的代码里面.htaccess

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

两项工程运行code,但使用ONY一个,不能同时使用。

0
Put this code in .htaccess file 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteBase /blog/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /blog/index.php [L] 
</IfModule>