WordPress site shows 404 error after modifying index.php file with URL update code

I added some code to the index.php file in my WordPress root directory to try and change my site URL. The code I used was:

update_option('siteurl', 'http://mysite.com');
update_option('home', 'http://mysite.com');

After adding this code, my entire WordPress site started showing a 404 not found error. I can’t access the admin panel either, and even trying wp-login.php gives me the same 404 error.

I already removed the code from the index.php file, but my website is still broken and showing the same 404 error. The site remains inaccessible even after removing the modifications. How can I fix this issue and get my WordPress site working again?

WordPress cached your URL changes - that’s why it’s still broken. After fixing the database, clear your caching plugins and check your .htaccess file. WordPress sometimes writes permanent redirects there that you’ll need to delete. Quick fix: add these two lines to wp-config.php right after the opening PHP tag: define(‘WP_HOME’,‘http://yoursite.com’); and define(‘WP_SITEURL’,‘http://yoursite.com’); - swap in your actual domain. This forces WordPress to use these URLs no matter what’s in the database. Once you’re back in, change the URLs through admin settings and remove those lines from wp-config.php.

Those functions ran when someone visited your site and permanently changed the URL settings in your database. Removing the code wasn’t enough - the database still has the wrong URLs stored. You’ll need to manually fix the database. Go into phpMyAdmin (or whatever database tool you use) and find the wp_options table. Look for rows where option_name is ‘siteurl’ and ‘home’, then update their option_value fields with your correct domain. If messing with the database feels scary, you can add some lines to your wp-config.php file instead. This’ll override the database values without touching them directly and should get you back into your site.

yeah, same thing happened 2 me. check if ur hosting provider changed something or if redirect rules are causing issues. it’s not always the database - server config might’ve gotten messed up when those functions ran. hit up ur host’s support team, they usually sort this out fast.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.