Changing the Site URL
There are four easy methods to change the Site URL manually. Any of these methods will work and perform much the same function.
Edit wp-config.php
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where "example.com" is the correct location of your site.
define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com');
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.
Edit functions.php
If you have access to the site via FTP, then this method will help you quickly get a site back up and running, if you changed those values incorrectly.
1. FTP to the site, and get a copy of the active theme's functions.php file. You're going to edit it in a simple text editor and upload it back to the site.
2. Add these two lines to the file, immediately after the initial "<?php" line.
update_option( 'siteurl', 'http://example.com' ); update_option( 'home', 'http://example.com' );
Use your own URL instead of example.com, obviously.
3. Upload the file back to your site, in the same location. FileZilla offers a handy "edit file" function to do all of the above rapidly; if you can use that, do so.
4. Load the login or admin page a couple of times. The site should come back up.
Important! Do not leave those lines in the functions.php file. Remove them after the site is up and running again.
Note: If your theme doesn't have a functions.php file create a new one with a text editor. Add the php tags and the two lines using your own URL instead of example.com:.
<?php update_option('siteurl','http://example.com'); update_option('home','http://example.com'); ?>
Upload that to your theme directory. Remove the lines or the remove the file after the site is up and running again.
>>>
Here are some additional details that step you through transfering a LAN-based wordpress site into an externally accessible site as well enabling editing the wordpress site from inside the LAN.
Two important keys are router/firewall modifications and the "wait 10+ minutes" after making the changes at the end.
-using ssh to log into your server (nano is a server preinstalled text editor)
-$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
-add lines just after <?php
-$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
-add lines just after <?php
update_option('siteurl','http://your.site.url:port/yourblog'); update_option('home','http://your.site.url:port/yourblog');
-refresh your web browser using your external site url
http://your.site.url:port/yourblog
-$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
-remove those lines you just added (or comment them out)
-access your router (these steps are for pfSense, other routers should have similar settings to look for/watch out for)
-add to firewall/nat table a line like this
-remove those lines you just added (or comment them out)
-access your router (these steps are for pfSense, other routers should have similar settings to look for/watch out for)
-add to firewall/nat table a line like this
wan/tcp/port/LAN.server.IP/80
-add to firewall/rules table a line like this
tcp/*/port/LAN.server.IP/port/*
-uncheck the box at System/advanced/network address translation/Disable NAT Reflection
"Disables the automatic creation of NAT redirect rules for access to your public IP addresses from within your internal networks. Note: Reflection only works on port forward type items and does not work for large ranges > 500 ports."
Then go do something for ten minutes and when you get back see if the external url http://your.site.url:port/yourblog from a LAN browser brings the page up correctly.
Relocate method
WordPress supports an automatic relocation method intended to be a quick assist to getting a site working when relocating a site from one server to another.
Code function
When RELOCATE has been defined as true in wp-config.php (see next chapter), the following code in wp-login.php will take action:
if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set
if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], , $_SERVER['PHP_SELF'] );
$url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
if ( $url != get_option( 'siteurl' ) )
update_option( 'siteurl', $url );
}
Steps
1. Edit the wp-config.php file.
2. After the "define" statements (just before the comment line that says "That's all, stop editing!"), insert a new line, and type:
define('RELOCATE',true);
3. Save your wp-config.php file.
4. Open a web browser and manually point it to wp-login.php on the new server. For example, if your new site is athttp://www.yourdomainname.com, then type http://www.yourdomainname.com/wp-login.php into your browser's address bar.
5. Login as per normal.
6. Look in your web browser's address bar to verify that you have, indeed, logged in to the correct server. If this is the case, then in the Admin back-end, navigate to Settings > General and verify that both the address settings are correct. Remember to Save Changes.
7. Once this has been fixed, edit wp-config.php and either completely remove the line that you added (delete the whole line), comment it out (with
//
) or change the true
value to false
if you think it's likely you will be relocating again.Note: When the RELOCATE flag is set to true, the Site URL will be automatically updated to whatever path you are using to access the login screen. This will get the admin section up and running on the new URL, but it will not correct any other part of the setup. Those you will still need to alter manually.
Important! Leaving the RELOCATE constant in your wp-config.php file is insecure, as it allows an attacker to change your site URL to anything they want in some configurations. Always remove the RELOCATE line from wp-config.php after you're done.
Changing the URL directly in the database
If you know how to access phpMyAdmin on your host, then you can edit these values directly to get you up and running again.
- Backup your database and save the copy off-site.
- Login to phpMyAdmin.
- Click the link to your Databases.
- A list of your databases will appear. Choose the one that is your WordPress database.
- All the tables in your database will appear on the screen.
- From the list, look for wp_options. Note: The table prefix of wp_ may be different if you changed it when installing.
- Click on the small icon indicated as Browse.
- A screen will open with a list of the fields within the wp_options table.
- Under the field option_name, scroll down and look for siteurl.
- Click the Edit Field icon which usually is found at the far left at the beginning of the row.
- The Edit Field window will appear.
- In the input box for option_value, carefully change the URL information to the new address.
- Verify this is correct and click Go to save the information.
- You should be returned to your wp_options table.
- Look for the home field in the table and click Edit Field. Note There are several pages of tables inside wp_options. Look for the> symbol to page through them.
- In the input box for option_value, carefully change the URL information to the new address.
- Verify this is correct and click Go to save the information.
Nenhum comentário:
Postar um comentário