最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

migration - Broken CSS after changing the site URL

programmeradmin3浏览0评论

I have a self-hosted Wordpress blog on my home server. Previously I accessed it directly via its original IP address taken from DHCP, but now I have configured a static IP address for it. The problem is that now all the CSS is broken.

I have updated my wp-config.php file adding the following two lines:

define('WP_HOME','http://192.168.0.100/myblog/');
define('WP_SITEURL','http://192.168.0.100/myblog/');

and I have restarted apache, but the CSS is still broken. Is there some other configuration file that I should update?

I have a self-hosted Wordpress blog on my home server. Previously I accessed it directly via its original IP address taken from DHCP, but now I have configured a static IP address for it. The problem is that now all the CSS is broken.

I have updated my wp-config.php file adding the following two lines:

define('WP_HOME','http://192.168.0.100/myblog/');
define('WP_SITEURL','http://192.168.0.100/myblog/');

and I have restarted apache, but the CSS is still broken. Is there some other configuration file that I should update?

Share Improve this question edited Apr 22, 2014 at 11:38 user1301428 asked Apr 21, 2014 at 22:27 user1301428user1301428 1431 gold badge1 silver badge5 bronze badges 8
  • 1 What are the addresses the stylesheets are being loaded from? – s_ha_dum Commented Apr 22, 2014 at 0:42
  • @s_ha_dum at the moment I am using the Twenty Thirteen theme and I haven't made any changes to it, so I would say everything is in the default theme folder. – user1301428 Commented Apr 22, 2014 at 11:37
  • 1 Have you updated the keys that you mention in the wp_options DB table? WP may still be looking for some resources at the old IP address. – David Gard Commented Apr 22, 2014 at 11:43
  • Didn't you change any file permissions. There was a similiar question on this here – Pieter Goosen Commented Apr 22, 2014 at 11:44
  • @DavidGard I haven't, but is it necessary? This page from the Codex seems to say that my edit should be enough: codex.wordpress/Changing_The_Site_URL – user1301428 Commented Apr 22, 2014 at 13:36
 |  Show 3 more comments

5 Answers 5

Reset to default 6

If you have access to your mysql you can update the wp-options table.

Before modification...

$ mysql -u <db_user> --password=<db_pwd> -D <db_name> <<<"select * from wp_options where option_name in ('siteurl', 'home');"
+-----------+-----------------+---------------------------------------------------------------------------------------------------+----------+
| option_id | option_name     | option_value                                                                                      | autoload |
+-----------+-----------------+---------------------------------------------------------------------------------------------------+----------+
|         1 | siteurl         | http://172.17.0.2/wordpress                                                                       | yes      |
|         2 | home            | http://172.17.0.2/wordpress                                                                       | yes      |
+-----------+-----------------+---------------------------------------------------------------------------------------------------+----------+

Then I changed the ip to 172.17.0.4 with this...

$ mysql mysql -u <db_user> --password=<db_pwd> -D <db_name> <<<"update wp_options set option_value='http://172.17.0.4/wordpress' where option_name in ('siteurl', 'home');"    

So the table becomes...

+-----------+-----------------+---------------------------------------------------------------------------------------------------+----------+
| option_id | option_name     | option_value                                                                                      | autoload |
+-----------+-----------------+---------------------------------------------------------------------------------------------------+----------+
|         1 | siteurl         | http://172.17.0.4/wordpress                                                                       | yes      |
|         2 | home            | http://172.17.0.4/wordpress                                                                       | yes      |
+-----------+-----------------+---------------------------------------------------------------------------------------------------+----------+

In some scenarios it could be useful to automatically update this configuration.

The WordPress Codex 'Changing The Site URL' states the following -

Note: Both settings should include the http:// part and should not have a slash "/" at the end.

I notice in your question that both the WP_HOME and WP_SITEURL constants include the trailing slash. This means that the URL to your style-sheet will be in this format -

http://192.168.0.100/myblog//wp-content/themes/my-theme/style.css'

In short, remove the trailing slash from both declarations and it should fix the problem.

Note also that the aforementioned Codex states the following in relation to the solution that you have chosen.

This is not necessarily the best fix, it's just hardcoding the values into the site itself. You won't be able to edit them on the General settings page anymore when using this method.

I suggest using one of the other more permanent methods described to achieve your goal.

Migrating your WordPress site to another location should be a painless process: you just have to export your database, import it to the new host, move your files there, configure everything and make the new site live. However, there are some steps that, when not done right, could provoke several problems that cause trouble and lead to unsuccessful site transfers.

For some reason, changing the URL from the GUI worked (after restoring the machine to the old IP address). Go figure.

For any reason my site URL had an extra space at the end of the line in the DB - wp-options

发布评论

评论列表(0)

  1. 暂无评论