在 Localhost 中更改站点 URL 和 WordPress URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29697144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change site URL and WordPress URL in Localhost
提问by vikal singh
I am work in Wordpress. And my system localhost url is http://localhost:8080/wordpress.
I want to shift our site another system.
我在 Wordpress 工作。我的系统本地主机 url 是http://localhost:8080/wordpress。
我想将我们的网站转移到另一个系统。
My problem is that my another system localhost url is http://localhost/wordpress(not include 8080). So can you help me that is how many table update in our database
我的问题是我的另一个系统本地主机 url 是http://localhost/wordpress(不包括 8080)。所以你能帮我看看我们数据库中有多少表更新吗
回答by iurii
I use the following queries to update domain name of the site
我使用以下查询来更新站点的域名
UPDATE wp_options
SET option_value = 'http://new-domain-name.com'
WHERE option_name = 'home';
UPDATE wp_options
SET option_value = 'http://new-domain-name.com'
WHERE option_name = 'siteurl';
UPDATE wp_posts
SET post_content = REPLACE(post_content,'http://old-domain-name.com','http://new-domain-name.com');
UPDATE wp_posts
SET guid = REPLACE(guid,'http://old-domain-name.com','http://new-domain-name.com');
Just change http://old-domain-name.comand http://new-domain-name.comto appropriate domain names. This should help you.
只需将http://old-domain-name.com和http://new-domain-name.com更改为适当的域名即可。这应该对你有帮助。
回答by Manish Shukla
Search replace db is a good tool to replace all old url with new urls. You can download latest file from
Search replace db 是一个用新 url 替换所有旧 url 的好工具。您可以从以下位置下载最新文件
Perform following steps
执行以下步骤
- put the file on wp directory
- open wp config file and change database credentials
- open url in browser (http://localhost/wordpress/downloadedfile.php)
- read instruction and go to next step till it complete.
- 将文件放在 wp 目录中
- 打开 wp 配置文件并更改数据库凭据
- 在浏览器中打开 url ( http://localhost/wordpress/downloadedfile.php)
- 阅读说明并转到下一步直到完成。
This tool help you to upload or migrate database from localhost to server or server to server.
此工具可帮助您将数据库从本地主机上传或迁移到服务器或服务器到服务器。
回答by ianmjones
You have to be very careful about the search and replace and ensure that any serialized data in any of your tables is properly unpacked, updated and re-packed.
您必须非常小心地进行搜索和替换,并确保任何表中的任何序列化数据都已正确解包、更新和重新打包。
If your target site is usable you can use various things to update its data to use the new URL format.
如果您的目标站点可用,您可以使用各种方法更新其数据以使用新的 URL 格式。
If you're comfortable with the command line you can use the WP-CLIwith a command like:
如果您对命令行感到满意,则可以将WP-CLI与以下命令一起使用:
wp search-replace http://localhost:8080/wordpress http://localhost/wordpress
For a WordPress Admin Dashboard tool I'd recommend the free Better Search Replaceplugin.
对于 WordPress 管理仪表板工具,我推荐免费的Better Search Replace插件。
If the URL needs to be changed before loading the data into the new site's database, I'd recommend using the free WP Migrate DBplugin to export your database with a find/replace pair of "//localhost:8080/wordpress" and "//localhost/wordpress" (without quotes). You can then run the exported SQL file against your target site's database.
如果在将数据加载到新站点的数据库之前需要更改 URL,我建议使用免费的WP Migrate DB插件通过查找/替换对“//localhost:8080/wordpress”和“ //localhost/wordpress”(不带引号)。然后,您可以针对目标站点的数据库运行导出的 SQL 文件。
回答by Marco Rubio
Log in to your WordPress control panel (http://coolexample.com/wp-admin, where coolexample.com is your domain name).
Click Settings, and then click General.
In the WordPress address (URL) and Site address (URL) fields, enter the new domain name or URL you want to use, and then click Save Changes.
登录到您的 WordPress 控制面板(http://coolexample.com/wp-admin,其中 coolexample.com 是您的域名)。
单击设置,然后单击常规。
在 WordPress 地址 (URL) 和站点地址 (URL) 字段中,输入要使用的新域名或 URL,然后单击保存更改。
see: https://www.godaddy.com/help/changing-your-wordpress-domain-name-6495
见:https: //www.godaddy.com/help/changed-your-wordpress-domain-name-6495
回答by Waleed Muaz
Fastest and Best Way to Change Go to WP-Config File and place that code
最快最好的更改方法转到 WP-Config 文件并放置该代码
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
回答by Anand
This are the steps, what I have done to make it success !,
这是步骤,我为使其成功所做的一切!,
1.Change the root folder name from \htdocs\OldSiteNameto \htdocs\NewSiteName.
1.将根文件夹名称从\htdocs\OldSiteName 更改为\htdocs\NewSiteName。
2.Change the wp-config.php
2.更改wp-config.php
From,
从,
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/OldSiteName');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/OldSiteName');
To,
到,
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/NewSiteName');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/NewSiteName');
3.Change the content in the .htaccessfile
3.更改.htaccess文件中的内容
From,
从,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /OldSiteName/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /OldSiteName/index.php [L]
</IfModule>
To,
到,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /NewSiteName/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /NewSiteName/index.php [L]
</IfModule>
4.Execute the scripts to change the values in the database.
4.执行脚本以更改数据库中的值。
UPDATE wp_options
SET option_value = 'http://127.0.0.1/NewSiteName'
WHERE option_name = 'home';
UPDATE wp_options
SET option_value = 'http://127.0.0.1/NewSiteName'
WHERE option_name = 'siteurl';
UPDATE wp_posts
SET post_content = REPLACE(post_content,'http://127.0.0.1/OldSiteName','http://127.0.0.1/NewSiteName');
UPDATE wp_posts
SET guid = REPLACE(guid,'http://127.0.0.1/OldSiteName','http://127.0.0.1/NewSiteName');
These are all the steps that I have done to make all the pages and inter links to get worked. eg:Clicking menu should take it the correct page.
这些是我为使所有页面和内部链接正常工作所做的所有步骤。例如:点击菜单应该把它带到正确的页面。
Note :Reference link : https://wordpress.org/support/article/changing-the-site-url/
注意:参考链接:https: //wordpress.org/support/article/changed-the-site-url/

