首页 > 解决方案 > Replace HTTP:// to HTTPS:// in WordPress

问题描述

With Google getting picky about HTTPS on sites, I was hoping to be able to do a quick and easy SQL Query to search & replace anything http:// with https://

I normally do something like the below for moving hosts:

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

So I tried to do something like

UPDATE `wp_commentmeta` SET 'meta_value' = REPLACE(`meta_value`, 'http://', 'https://');

But it didn't seem to work. Anyway to do the ENTIRE database at once?



If there is mySQL or htaccess script, I am more interested in those solutions.

标签: mysqlwordpresssslhttpsphpmyadmin

解决方案


如果您有权编辑.htaccess文件,则可以将以下内容添加到其中:

RewriteEngine on

# force SSL
RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

上面的代码将使用 301(永久)重定向,如果不想使用 301 重定向,您只需将最后一行的最后一部分从[L,R=301]更改为[L,R]

如果您想更彻底地替换 SQL,通常可以在列(特色图像)和列(反向链接等)内的posts表内找到所有必要的链接。然后当然也在表格内- 表格内的列和/ 。这是我通常使用的 SQL 查询:guidpost_contentpost_metameta_valuehomesiteurloptions

UPDATE wp_options SET option_value = replace(option_value, 'http://example.com', 'https://example.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE (guid, 'http://example.com', 'https://example.com');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://example.com', 'https://example.com');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://example.com','https://example.com');

推荐阅读