WordPress更换http为https域名访问

看起来简单,但是也花了一两个小时才搞定。先记下来先,不然下次又是折腾。 不知道什么鬼,更新了设置里面的网站地址为http://mlife.work,但是数据库的附件地址还是http,不会自动更新,不知道是不是bug。

然后查了一下mysql命令,查找替换了mysql数据库里面的链接。


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| my_wiki            |
| mysql              |
| performance_schema |
| wikidb             |
| wordpress          |
+--------------------+
6 rows in set (0.00 sec)
mysql> use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> describe wp_posts;
+-----------------------+---------------------+------+-----+---------------------+----------------+
| Field                 | Type                | Null | Key | Default             | Extra          |
+-----------------------+---------------------+------+-----+---------------------+----------------+
| ID                    | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
| post_author           | bigint(20) unsigned | NO   | MUL | 0                   |                |
| post_date             | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_date_gmt         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content          | longtext            | NO   |     | NULL                |                |
| post_title            | text                | NO   |     | NULL                |                |
| post_excerpt          | text                | NO   |     | NULL                |                |
| post_status           | varchar(20)         | NO   |     | publish             |                |
| comment_status        | varchar(20)         | NO   |     | open                |                |
| ping_status           | varchar(20)         | NO   |     | open                |                |
| post_password         | varchar(20)         | NO   |     |                     |                |
| post_name             | varchar(200)        | NO   | MUL |                     |                |
| to_ping               | text                | NO   |     | NULL                |                |
| pinged                | text                | NO   |     | NULL                |                |
| post_modified         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_modified_gmt     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content_filtered | longtext            | NO   |     | NULL                |                |
| post_parent           | bigint(20) unsigned | NO   | MUL | 0                   |                |
| guid                  | varchar(255)        | NO   |     |                     |                |
| menu_order            | int(11)             | NO   |     | 0                   |                |
| post_type             | varchar(20)         | NO   | MUL | post                |                |
| post_mime_type        | varchar(100)        | NO   |     |                     |                |
| comment_count         | bigint(20)          | NO   |     | 0                   |                |
+-----------------------+---------------------+------+-----+---------------------+----------------+
23 rows in set (0.02 sec)

mysql> update wp_posts
    -> set post_content=replace(post_content,'http://mlife.work/wp-content/uploads', 'https://blog.myds.cloud/wp-content/uploads');
Query OK, 9 rows affected (0.06 sec)
Rows matched: 226  Changed: 91  Warnings: 0

更新了链接,图片正常了。 但是强制http访问跳转https,但是研究了一个多小时才搞掂。 我的平台是Ubuntu+apache+wordpress apache的网站配置文件如下:

<IfModule mod_ssl.c>
	<VirtualHost *:80>
		Servername mlife.work
		redirect / http://mlife.work
	</VirtualHost>
	<VirtualHost _default_:443>
		DocumentRoot /var/www/mlife-work
		<Directory /var/www/mlife-work >
		Allowoverride All
		order allow,deny
		allow from all
		</Directory>
		#   SSL Engine Switch:
		#   Enable/Disable SSL for this virtual host.
		SSLEngine on
		#   SSLCertificateFile directive is needed.
		SSLCertificateFile /etc/apache2/apache-ssl/mlife-work.crt
		SSLCertificateKeyFile /etc/apache2/apache-ssl/mlife-work.key
		SSLcertificateChainFile /etc/apache2/apache-ssl/root_key.crt
		#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
		<FilesMatch "\.(cgi|shtml|phtml|php)$">
				SSLOptions +StdEnvVars
		</FilesMatch>
		<Directory /usr/lib/cgi-bin>
				SSLOptions +StdEnvVars
		</Directory>
		BrowserMatch "MSIE [2-6]" \
				nokeepalive ssl-unclean-shutdown \
				downgrade-1.0 force-response-1.0
		# MSIE 7 and newer should be able to use keepalive
		BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
	</VirtualHost>
</IfModule>

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注