Change URL on Wordpress - php

I have been working on a WordPress site.
www.example.com and the main homepage of my site(index.html) says "We're under construction etc." and it's just an image.
For the development of the website, I have been using a different directory - www.example.com/dev and everything I have developed has been under /dev(/dev/index.php etc.)
The website is now ready and I need to point the finsihed website (www.example.com/dev) to the actual public site(which is now under www.example.com) that I have finished. How do I go about this?

use this code for changing you website url
SET #oldsite='http://www.example.com/dev';
SET #newsite='http://www.example.com';
UPDATE wp_options SET option_value = replace(option_value, #oldsite, #newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, #oldsite, #newsite);
UPDATE wp_links SET link_url = replace(link_url, #oldsite, #newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, #oldsite, #newsite);

This can be done 2 ways,
You can do this easily by changing site_url in options table. Once you transfer data and change the url your site should be running on the new url. If you have stored static urls in post or pages then, you have to change that as well.
Export sql file from phpmyadmin. Now find and replace all urls from old to new ones.
Note: Keep your current development site working as, sometimes it's possible that contact form 7 or any data gets missing. For example, Widgets get in inactive mode sometime.
Once your new website is confirmed then you can remove your old website.

step 1:
Just copy your all files and folder from www.example.com/dev to www.example.com
step 2:
open your database and in table wp_option
siteurl
http:// www.example.com/dev to www.example.com/
home
http:// www.example.com/dev to www.example.com/

Moving Directories On Your Existing Server
Wordpress has a wiki page that explained this for you:
Moving Wordpress
Here are the step-by-step instructions to move your WordPress site to a new location on the same server:
Create the new location using one of these two options:
If you will be moving your WordPress core files to a new directory,
create the new directory.
If you want to move WordPress to your root directory, make sure all
index.php, .htaccess, and other files that might be copied over are
backed up and/or moved, and that the root directory is ready for the
new WordPress files.
Log in to your site.
Go to the Administration > Settings > General panel.
In the box for WordPress Address (URL): change the address to the
new location of your main WordPress core files.
In the box for Site Address (URL): change the address to the new
location, which should match the WordPress (your public site)
address.
Click Save Changes.
(Do not try to open/view your site now!)
Move your WordPress core files to the new location. This includes
the files found within the original directory, such as
http://example.com/wordpress, and all the sub-directories, to the
new location.
Now, try to open your site by going to yourdomain.com/wp-admin.
Note, you may need to go to yourdomain.com/wp-login.php
If you are using Permalinks, go to the Administration > Settings > Permalinks
panel and update your Permalink structure to your
.htaccess file, which should be in the same directory as the main
index.php file.
Existing image/media links uploaded media will refer to the old
folder and must be updated with the new location. You can do this
with the Better Search Replace plugin, WP-CLI's search-replace if
your hosting provider (or you) have installed WP-CLI, manually in
your SQL database, or by using the 3rd party database updating tool
Search and Replace Databases Script * Note: this script is best used
by experienced developers.
In some cases your permissions may have changed, depending on your
ISP. Watch for any files with 0000 permissions and change them
back to 0644.
If your theme supports menus, links to your home page may still have
the old subdirectory embedded in them. Go to Appearance > Menus and
update them.
Sometimes you would need to restart your server,
otherwise your server may give out an error. (happens in MAMP
software (Mac)).
It is important that you set the URI locations BEFORE you move the
files.
If You Forget to Change the Locations
If you accidentally moved the files before you changed the URIs: you have two options.
Suppose the files were originally in /path/to/old/ and you moved them to /path/to/new before changing the URIs. The way to fix this would be to make /path/to/old/ a symlink (for Windows users, "symlink" is equivalent to "shortcut") to /path/to/new/, i.e.
ln -s /path/to/new /path/to/old
and then follow the steps above as normal. Afterwards, delete the symlink if you want.
If you forget to change the WordPress Address and Blog Address, you will be unable to change it using the wordpress interface. However, you can fix it if you have access to the database. Go to the database of your site and find the wp_options table. This table stores all the options that you can set in the interface. The WordPress Address and Blog Address are stored as siteurl and home (the option_name field). All you have to do is change the option_value field to the correct URL for the records with option_name=’siteurl‘ or option_name=’home‘.

Related

WP-Admin redirects to old URL (after editing config.php)

I am trying to get a client's WordPress site copied over to my company's server to use as a development site. I've ran into an issue when trying to log into the site's administrator panel; it redirects us to the existing site's URL instead (ending up as [OLD SITE]/[NEW URL]/wp-admin). Additionally, trying to go to any page other than the homepage gets a 404.
I've tried editing the wp-config and defining the WP_HOME and WP_SITEURL there, with no success. In a previous attempt we used a backup tool that was meant to replace references to the old URL with the new URL, and on another we ran queries and checked through wp-options in the database to be sure that we caught all of the old references. Still redirects to the old site.
We've tried restoring from two backups, Akeeba and BackUpWordPress. Our current attempt is a copy we've downloaded directly and then uploaded (with an imported SQL backup).
Another odd thing I've noted is that changing one of the URLs in the database causes more issues. Mainly, if I update the URL of 'wordpress-https_ssl_host' in the wp-options table, the theme breaks. Not sure where to go with this from here.
I'm always succesfully using the following script : search & replace:
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
in order to update a wordpress site url.
Just copy the provided code in a directory under your site, then launch the provided index.php in a browser: the database infos should be automatically determined. Then specify the old and new urls and click on "Run" !
Don't forget to remove the created directory afterwards.
For solving this issue you have to change siteurl in database wp_options table
option_name = siteurl where
option_value = YOUR OLD SITE URL
change your old site url and update it with your local developement site URL
Hope this will help you..
We found the problem; as it turns out it was nothing to do with anything from the default WordPress files. The client was using an extension called WordPress HTTPS, and apparently that was causing a conflict somewhere. We renamed the extension's folder to disable it and everything ran fine. I imagine it was overriding what we were setting in wp-config.

How to move wordpress to subdirectory

I am moving a brand new Wordpress site from root "/" directory to a subdirectory "/wordpress/" using the following guide:
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Sadly, there are problems with these steps.
Step (4) indicates we need to update "Site address (URL)" which updates wp_option "siteurl" to "http://localhost/" but will leave "home" in tact (http://localhost/wordpress).
This is causing issues as I can no longer login to wp-admin. By setting both "siteurl" back to "http://localhost/wordpress" I am finally able to access wp-admin, but now the pages are throwing 404's and cannot be found. Not only that, but all URL's have /wordpress/ in the path now which isn't a slug I want in my pages. In other words, I am fine with having wp-admin accessible via http://localhost/wordpress/wp-admin/ but public pages should be accessible using this format: http://localhost/page-1/
Is there a way to move WP to a subdirectory without all these consequences?
Step 1: Export your database as .sql open the file using text editor. find the http://localhost and replace with http://localhost/wordpress and again import it. This will work.!
Step 2: Update siteurl and home
Next you need to change the location of your site in the database.
In wp_options, locate siteurl and home. Usually these records are at the top of the table on line 1 and 2.
For siteurl, click the field under option_value and replace the old domain with your new domain name.
Press enter to save.
Do the same for home.
Step 3: Fix permalinks (Optional)
If you experience that you get a 404 error when you try to open links on your site, the Permalinks are broken. Luckily it is very easy to fix this.
Log in to your WordPress dashboard.
Click Settings and then Permalinks
Scroll down and click Save Changes.

wp-admin can't access after moving

I need mention that I had google search the solution before post at here.
I move my wordpress site to another domain and different server.
wp_config.php edited; database, database username, passwword, and host all changed. table_prefix remain the same because i use the same one.
wp_posts and wp_option i had changed too.
I still got this error message anyway.
You do not have sufficient permissions to access this page
Anyone know what happen and how to fix this ?
wp-admin can't access after moving
If you are moving your domain without changing the Home and Site URLs of your WordPress site you can follow the below guidelines as prescribed by the wordpress codex.
If database and URL remain the same, you can move by just copying your files and database.
If database name or user changes, edit wp-config.php to have the correct values.
If you want to test before you switch, you must temporarily change "siteurl" and "home" in the database table "wp_options" (through phpMyAdmin or similar).
If you had any kind of rewrites (permalinks) setup you must disable .htaccess and reconfigure permalinks when it goes live.
EDIT (if your site url has also changed, well i am only phrasing from the codex site)
Moving a website and changing your domain name or URLs (i.e. from http://example.com/site to http://example.com, or http://example.com to http://example.net) requires the following steps - in sequence.
Download your existing site files.
Export your database - go in to mySQL and export the database.
Move the backed up files and database into a new folder - somewhere safe - this is your site backup.
Log in to the site you want to move and go to Settings > General, then change the URLs. (ie from http://example.com/ to http://example.net ) - save the settings and expect to see a 404 page.
Download your site files again.
Export the database again.
Edit wp-config.php with the new server's mySQL database name, user and password.
Upload the files.
Import the database on the new server.
When your domain name or URLs change there are additional concerns. The files and database can be moved, however references to the old domain name or location will remain in the database, and that can cause issues with links or theme display.
If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break. To avoid that serialization issue, you have two options:
Only perform a search and replace on the wp_posts table.
Use the Search and Replace for WordPress Databases Script to safely change all instances.
Make sure that the web server is allowing you to view the page itself, and look in the httpd.conf or .htaccess file for the directory that the main Wordpress script lives in.
Make sure that the Wordpress files have the correct permissions. If you just copied them over, then the user that needs to accesses them (apache on many typical LAMP installs, but yours may be different) is able to.
If you have already copied all your files and moved all of it to the new directory, then all you need to do is set your site url, home url.
So for example, if you are working on wordpress locally, you might have had your original URL to something like this:
http://localhost/wordpress
and your new URL might be something like this:
http://wordpress.local
In the case above, you would need to modify your settings in the database.
Database settings:
Go to the wp_options table, and look for the column named option_name, look at the field that says siteurl and home. You will notice that next to them in the option_value field you had your old URL. Change this to your new URL, and you should be good to go.
Hope this helps.

moving a wordpress website to a different url

I have a wordpress website for a minecraft server, the server name changed, so the website domain changed. I tried moving the forums to the other url, by coping and pasting all the files but using the same exact database. However, as you use website, it links you back to the original website a lot. If is the problem that the main domain name is inside the mysql database? If i change all domains inside the database, will this fully move the website?
Thanks
In your wp-config.php file, enter the line define('RELOCATE',true);
Access your login page from http://yoursiteurl.com/wp-login.php, go to settings and change the site url.
Remove define('RELOCATE',true); from wp-config.php
Wordpress has a whole guide on moving wordpress sites: http://codex.wordpress.org/Moving_WordPress
but the basic step is as follows:
goto: Administration > Settings > General panel, and change the site URLs there to your new url. this should update all post links, etc. in the database.
move files to new host
move database to new host.
Moving a WordPress web site is quite well documented here:
http://codex.wordpress.org/Moving_WordPress
If not, it really is just as simple as copying all the files and the database. To avoid FTP transmission errors and such, I have had more luck with compressing all the files into a single .tar.gz file then FTP'ing that to my computer and to the new web site, where I expand it.
Personally, I use cPanel (the most popular web hosting customer account/web site management tool). Their Backup and Restore for the database. And their File Manager's Compress and Expand to work with the .tar.gz
Changing domain names significantly complicates matters. I use the Search and Replace plug-in to handle hard-coded URLs. Or manually find and replace the URL in the database script.
Run this SQL to change url's in db.
UPDATE wp_posts SET guid = REPLACE(guid, 'old-url.com', 'new-url.com');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'old-url.com', 'new-url.com');
UPDATE wp_options SET option_value = REPLACE(option_value, 'old-url.com', 'new-url.com');

Wordpress local server to live host

I am developing a wordpress site. I uploaded the files(wordpress) to my live host. So my new live url site for my wordpress like this sample url http://mywordpress.com/, the display seems to be fine, but when I start browsing the menus page will be redirected to my local server, instead of http://mywordpress.com/about-us/ it went to my localhost like http://localhost/mywordpress/about-us
So when I checked the page source all the links including the stylesheet is link to my local. even though I use this code
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css" media="all" />
Its kinda weird... but anyone knows how to configure this?
It sounds to me like your database may be using old values for your url's.
For a quick solution that may or may not solve your issue, try http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/ . It's a great plugin. If not... here are my bullet proof instructions for transferring from local to online.
I've migrated from local to online hundreds of times and I think most tutorials on wordpress migration are overly complex. Here's my method (assuming you already have a fresh wordpress installation and database)
Go to phpMyAdmin for your local server and export your database (but not as a file)... just get the straight SQL text and copy it.
Paste that code into dreamweaver, text editor, coda or any plaintext word processor that can do a search and replace. Then search for "http://MyOldWordpressUrl.com/wordpress" (make sure there is NO slash after the final directory) and replace with "http://MyNewWordpressUrl.com/wordpress". Obviously don't include the quotation marks. Make sure your old wordpress URL is correct. You can double check in admin -> general settings.
Get into your control panel for your online hosting and go to the database for your new wordpress install (this should be a brand new installation where you haven't yet created any posts or input any data-- just what wordpress gives you). Export the database and save it as a file (just in case). Now drop all the tables. Click YES when it asks you if you're sure. Then click on the SQL icon (should be in the upper left hand corner of the left sidebar). This should open a new window. Now paste in your code from step 2 and click GO.
Transfer your theme folder via FTP.
Right now you should go to the new wordpress install's wp-admin. Your same User Name and password will apply. Go to "add a post" and add any image from your computer... wait for it to upload, now delete it. This step is to have the server create the uploads folder to be 100% certain is registered by wordpress and set to the correct permissions. I've wasted hours before by transferring the uploads folder directly by FTP, so don't do it.
Step 5 created an uploads folder in FTP, now you can drag and drop the contents of your uploads folder (ie 2008, 2009, 2010, 2011 + subfolders) into the uploads folder. There should be nothing in it except an empty folder (because you deleted that file in step 5), so it's fine to overwrite if it warns you.
The only remaining step is to transfer your plugins. You can do it via FTP, although it's probably faster to add them directly through the Wordpress admin via "add plugin" and search + install.
Oh yeah, now go to permalink settings and click "default", update, then choose whatever you want-- you need to refresh permalinks to.
That's foolproof... but you have to be somewhat familiar/confident using PHP myadmin. Although I've founds some widgets do not transfer via this method, so you may have to drag and drop some widgets again (appearance -> widgets) after the transfer.
For clarification on step 1 and step 3, see the diagrams here: http://webdesignerwall.com/tutorials/exporting-and-importing-wordpress ... but the rest of that WDW tutorial is guaranteed to give you problems at somepoint.
As mentioned in the comments, you will need to browse to the Settings->General page and update your site URL and wordpress URL.
If you can't get to the Settings page because you get redirected to your local site (this has happened to me before), you may have to edit the values in mysql directly, which isn't too bad, really.
The settings are located in the wp_options table under the option_name "siteurl" and "home". If you need more help with that, post a comment.
You may need to refresh your permalinks: see step 5 below. Official documentation on this subject may clear some things up as well.
Steps to move a local WordPress install to a live site
This is my method, and it has worked every time. Assume local WP install is at http://localhost/wordpress/ with WP database named wordpress and live WP install is at http://livesite.com/ with WP database named livesite:
Create a backup of local WP database -
navigate to http://localhost/phpmyadmin
select database wordpress from side menu
click EXPORT
check the box for Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT statement
click GO - it should download a file called wordpress.sql
Download a database for the live site -
sign in + navigate to http://localhost/wordpress/wp-admin/options-general.php
enter the live site values for WordPress Address (URL) and Site Address (URL)
click SAVE CHANGES - this will break your local WP installation: that's why we made the backup
repeat step 1 [Create a backup of local WP database] - include all substeps
rename this newly downloaded file from wordpress.sql to livesite.sql
Prepare WP files for live site
upload WP file structure to http://livesite.com/
edit /wp-config.php to have live database name, username and password
Import live WP database - if you haven't created the livesite database yet, do so now
navigate to http://livesite.com/phpmyadmin or equivalent
select database livesite from side menu
click IMPORT
choose local file livesite.sql from step 2
click GO - it should successfully import the livesite database
Refresh live site permalinks - your permalinks are set correctly but not updated to reflect the new domain, so get WP to update them
navigate to http://livesite/wp-admin/options-permalink.php
click SAVE CHANGES
it should alert permalink structure updated. If not make a frivolous change to get it to do so, e.g. change permalink structure and then revert
Revert local installation - this can really be done at any point after step 2.
Follow step 4 from http://localhost/phpmyadmin using the backup created in step 1. This is the only way to fix the local install because we changed the domain in step 2 and we can't even get back to the settings page.
NOTES
using WP 3.3.1
using phpMyAdmin 3.4.8
The reason behind this, After you move wordpress site from local server to live you not changed the site url and home address.So, when ever you try to open your site in real server it will redirect back to your local server.You need to open PhpMyAdmin Tool in Cpanel or FTP and select your database then open wp_options table.
In wp_options table change the value of site url and home.
Now your problem will solved.

Categories