sql 查询将WP从“http”切换到“https”以进行SSL配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 查询将WP从“http”切换到“https”以进行SSL配置相关的知识,希望对你有一定的参考价值。

-- Update any embedded attachments/images that use http.
-- This one updates the src attributes that use double quotes:

UPDATE `wp_posts` SET post_content = REPLACE(post_content, 'src="http://www.yoursite.com', 'src="https://www.yoursite.com')
WHERE post_content LIKE '%src="http://www.yoursite.com%';

-- This one takes care of any src attributes that use single quotes:
UPDATE `wp_posts` SET post_content = REPLACE(post_content, "src='http://www.yoursite.com", "src='https://www.yoursite.com")
WHERE post_content LIKE "%src='http://www.yoursite.com%";

-- Update any hard-coded URLs for links. This one updates the URL for href attributes that use double quotes:

UPDATE `wp_posts` SET post_content = REPLACE(post_content, 'href="http://www.yoursite.com', 'href="https://www.yoursite.com')
WHERE post_content LIKE '%href="http://www.yoursite.com%';

-- This one updates the URL for href attributes that use single quotes:

UPDATE `wp_posts` SET post_content = REPLACE(post_content, "href='http://www.yoursite.com", "href='https://www.yoursite.com")
WHERE post_content LIKE "%href='http://www.yoursite.com%";

-- Update any “pinged” links:

UPDATE `wp_posts` SET pinged = REPLACE(pinged, 'http://www.yoursite.com', 'https://www.yoursite.com')
WHERE pinged LIKE '%http://www.yoursite.com%';

-- This step is just a confirmation step to make sure that there are no remaining http URLs for your site in the wp_posts table, except the GUID URLs.

SELECT *  FROM `WP_DB_NAME`.`wp_posts` WHERE (CONVERT(`ID` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_author` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_date` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_date_gmt` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_content` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_title` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_excerpt` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_status` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`comment_status` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`ping_status` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_password` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_name` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`to_ping` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`pinged` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_modified` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_modified_gmt` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_content_filtered` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_parent` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`menu_order` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_type` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`post_mime_type` USING utf8) LIKE '%%http://www.yoursite.com%%' OR CONVERT(`comment_count` USING utf8) LIKE '%%http://www.yoursite.com%%');

-- This changes any comment author URLs that point to the http version of your site. This is in case you’ve ever replied to a comment while your URL was pointing to http.

UPDATE `wp_comments` SET comment_author_url = REPLACE(comment_author_url, 'http://www.yoursite.com', 'https://www.yoursite.com')
WHERE comment_author_url LIKE '%http://www.yoursite.com%';

-- This updates the content of the comments on your site. If there are any links in the comments that are linking to an http URL on your site, they will be updated to https.

UPDATE `wp_comments` SET comment_content = REPLACE(comment_content, 'http://www.yoursite.com', 'https://www.yoursite.com')
WHERE comment_content LIKE '%http://www.yoursite.com%';

-- Now we move to the wp_postmeta table. This takes care of any custom post meta that points to the http version of your site.

UPDATE `wp_postmeta` SET `meta_value` = REPLACE(meta_value, 'http://www.yoursite.com', 'https://www.yoursite.com')
WHERE meta_value LIKE '%http://www.yoursite.com%';

以上是关于sql 查询将WP从“http”切换到“https”以进行SSL配置的主要内容,如果未能解决你的问题,请参考以下文章

尽管有斜线,但查询将 http 重写为 https?

如何将负载均衡器从 HTTP 切换到 HTTPS?

使用新的 wp_query 将 sql 查询转换为 wordpress 查询

http 到 https – 无法访问 wp-admin

WP7 SQL Server CE 查询优化

从 http 切换到 https 时,Magento 会话丢失