mysql - 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?
- I have tried a few options on S.O.F., but nothing worked well.
- I prefer not to have to install a plugin as a "fix"
If there is mySQL or htaccess script, I am more interested in those solutions.
解决方案
如果您有权编辑.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 查询:guid
post_content
post_meta
meta_value
home
siteurl
options
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');
推荐阅读
- python-3.x - 在单个文档中翻译多种语言的问题
- java - 如何将日期从 (ddmmyyyy HH:mm:ss) 转换为 (yyyy-MM-dd HH:mm:ss.SSS)?)
- excel - 计算每小时奖金
- excel - 如何复制超出范围的数据
- jquery - Chartjs 多个条形图,第一个数据会偏移过视图
- r - R中的列表到数据框的转换:保留列表索引
- facebook - Facebook 不会在 Facebook 页面的“关于”部分接受我们网站的 URL?
- substrate - 在 Substrate 中,code: 1012 “Transaction is暂时禁止”是什么意思?
- android - 在我的 android 工作室中找不到“libjniavutil.so”
- git - Git:仅将已提交的更改推送到当前分支