PHP Script to Reset WordPress URL

Are you looking for a PHP script that can reset the WordPress Address (URL) of your blog? or Did you accidentally change the settings of the Blog Address (URL) from General settings then you were not able to access your blog because of this modification that you made?

Wordpress Adress URL

Now to solve my problem, I have prepared a PHP script to reset it to my original blog settings. Here’s the PHP script for the WordPress address URL reset that I used:

<?php
$dbhost = ‘localhost’;
$dbuser = ‘user_name’;
$dbpass = ‘password‘;
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(’Error connecting to mysql’);
$dbname = ‘databasename’;
mysql_select_db($dbname);
$query  = “UPDATE wp_options SET option_value = ‘http://www.urdomain.com‘ WHERE `wp_options`.`option_id` =1 AND `wp_options`.`blog_id` =0 AND CONVERT( `wp_options`.`option_name` USING utf8 ) = ’siteurl’ LIMIT 1 ;”;
$result = mysql_query($query);
$query = “UPDATE wp_options SET option_value = ‘http://www.urdomain.com’ WHERE `wp_options`.`option_id` =39 AND `wp_options`.`blog_id` =0 AND CONVERT( `wp_options`.`option_name` USING utf8 ) = ‘home’ LIMIT 1 ;”;
$result = mysql_query($query);
mysql_close($conn);
?>

You can download the whole script here: reseturl.txt and modify the portion (underlined option above) that is applicable to your site. Rename the file to reseturl.php then upload it to your website. Execute it and that’s all it will reset the WordPress Address (URL) and Blog Address (URL) to appropriate URL.

I hope this script will solve your WordPress problem.

Related posts:

  1. Just Upgraded to WordPress 2.8.5
  2. Why Your WordPress Blogs Are Not Crawled?
  3. WordPress 2.6 Now Available

Both comments and pings are currently closed.

20 Responses to “PHP Script to Reset WordPress URL”

  1. eamills says:

    Again I screwed up, and again this helped! Thanks again

  2. abhijeet says:

    Thanks for this.
    I was really fall in Big problem.
    You save me!
    Thanks A lot!

  3. bleuken says:

    You may send it to me shezoom and let me see if I can do anything about it.

  4. shezoom says:

    I continue to receive errors…and have tried several variations on the reseturl.php including wonderful statements such as

    Parse error: syntax error, unexpected T_STRING in /home/content/m/b/s/mbsuccess777/html/blog/reseturl.php on line 5

    So then I took a look at the wp-config.php file…located the database name and info…and now get things like

    Error establishing a database connection

    Could I forward you both files … am so lost I’m feeling blonder each and every moment.

  5. bleuken says:

    Hi shezoom! it should be uploaded on your server where your WP was installed. Then change its attribute to executable (CHMOD 777) then run it via yoururl.com/reseturl.php

    make sure you delete the file after you use it.

  6. shezoom says:

    this sounds awesome! however how to you actually install it/run it? I made all of the recommended modifications in the script within notepad, saved it as a .php file, uploaded it to my site.

    Just don’t know where to go from here…

  7. Sci-Fi Si says:

    Great stuff! Thanks for that :)

  8. bleuken says:

    thanks, the URL changed when I transfer this site to another hosting. I’ve just corrected it, thanks. You can download it right now.

  9. Sci-Fi Si says:

    It’s ok thanks. I went in to MySQL query browser and reset it there. Even though I couldn’t get the script working it does have the table name and ID number so I knew which values to change back.

    Many thanks

  10. Sci-Fi Si says:

    Humm…

    I have copied the script you have above into a text editor and saved it as reseturl.php but unfortunately I get:

    PHP Parse error: parse error in \thisisnotmywebsiteurl\reseturl.php on line 5

    I then tried to download the script link you have reseturl.txt, but unfortunately I get a Error 404.

    Do you know what is happening??

    Many thanks

  11. eamills says:

    Thanks so much for this! I’m a complete novice and I was able to get this work! Thanks again. This should be in the official WordPress documentation.

  12. timewarpJFC says:

    Okay bleuken you are a life saver! After I reset all the data you mentioned above, the script worked like a charm. Thanks a million, the ite is back up and running……. http://www.ovr25.com :-)

  13. bleuken says:

    Hi Look for this portion on your file wp-config.php

    define(‘DB_NAME’, ‘name-of-database‘); // The name of the database

    define(‘DB_USER’, ‘database-user‘); // Your MySQL username

    define(‘DB_PASSWORD’, ‘database-password‘); // …and password

    define(‘DB_HOST’, ‘localhost‘); // 99% chance you won’t need to change this value

    look for this values (on bold) and replace the value on the resetphp.url, if you want send me an email with the wp-config.php then I will send you the script.

  14. timewarpJFC says:

    bleuken sorry to be such a hassle I am not a database or web gurru and at a loss, and scard I have messed my whole site up. I

    I followed the instructions and I added the db username and db password as you mentioned above and copied them out of the wp-config file. Then I uploaded the renamed script of reseturl.php to the http://crownen.com/ovr25/ directory as you mentioned nothing happened. I tried typing the following in the browser http://www.crownen.com/ovr25/reseturl.php and this came up.

    Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/usr/local/mysql-5.0/data/mysql.sock’ (2) in /home/content/t/i/m/timewarpjfc/html/ovr25/reseturl.php on line 5
    Error connecting to mysql

    http://crownen.com/ovr25/ is the sub directory that my site is uploaded to.

    This all came from me accidentally typing in the url masking that I am using in the URL field in wordpress. I inserted http://www.ovr25.com and not http://www.crownen.com/ovr25 the sub directory a I should have.

    any tips or guidance…

  15. bleuken says:

    @timewarpJFC, you should upload the script to your server after following the renaming instruction and replace user id and password with yours on the script which can be found from wp-config.php

  16. timewarpJFC says:

    noob question here how do you execute the script?

  17. Robin says:

    I cannot thank you enough for this script. It just saved my life! Well, maybe not my life, but over a month’s worth of work, that’s for sure.

    You rock!

  18. thewump says:

    Oh man, you just saved my ass.. In an incredibly limited access environment where all I can do is edit files.. no ssh etc. Just pasted this into the top of index.php, ran it, then removed it.

    Thanks.

    Keith

  19. bleuken says:

    Yes that’s right. Delete the file after use, which i did after I’m done with it! Thanks Al! :D

  20. Alfonso says:

    …and make sure to delete the file from your server afterwards :)

Subscribe to RSS Feed Follow me on Twitter!