How To Remove "www." From a WordPress Site URL

Posted on 12 May 2014 in Blog Posts, WordPress
Comments: 0

At one point, I wanted to remove all references to www. that appears before the domain name in the address bar for hosted Wordpress websites.

I didn't want to use plugins and so I went through all the files and databases related to the WordPress installation to make the changes manually.

I wrote down what I did and it should work for you.

The instructions:

  1. In WordPress admin, go to Settings > General and, if it exists, remove the "www." part of the address in the WordPress Address (URL) and also in the Site Address (URL) (e.g. replace "https://www.karavadra.net" with "https://karavadra.net".
  2. Export an SQL dump that has the DROP TABLES IF EXISTS and CREATE TABLES commands for the MySQL tables that runs the WordPress site.
  3. Make a backup of this SQL dump if you need to revert back to it and use a working version of the file to make changes.
  4. In your preferred text editor open the working version of the SQL dump and replace all instances of the URL with "http://" followed by "www." with the same text  without the "www." part (e.g. replace "https://www.karavadra.net" with "https://karavadra.net").
  5. Next replace all instances of "www.karavadra.net" with "karavadra.net". This will remove the "www." part in links within content.
  6. If the path to your server root directory uses the "www." part of the URL, then the replacement in point 5 above will have made your server root address incorrect and this will need to be corrected. Your server root directory can be found by creating a PHP file with the code below, FTPing it to your server root and then accessing it using your browser. For example if you create a PHP file called server-root.php with the code below then in your browser enter it's URL (e.g. https://www.karavadra.net/server-root.php).
    <?php
    echo $_SERVER['DOCUMENT_ROOT'];
    ?>

    The browser should display the server root directory: (e.g. "/home/myserver/1234/www.karavadra.net/public_html").
    If the domain part of the server root directory has the "www." in it like the example above then the replacement in point 5 above will have to be put back as follows, otherwise you can skip this step.In your working version of the SQL dump, replace all instances of (for example) "/home/myserver/1234/karavadra.net/public_html" with "/home/myserver/1234/www.karavadra.net/public_html" (simply putting the "www." back into the server root path).

  7. Save the changes in the working version of the SQL dump and import it into the WordPress site's MySQL database.

The above instructions should remove the www. from the address bar.

Now test your WordPress site without the "www." and also test the links throughout the template and content.

If there are any issues then import the backed up version of the MySQL dump and you should be back where you started.

Share this:

Tags


Leave a Reply

Your email address will not be published. Required fields are marked *

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
Do NOT follow this link or you will be banned from the site!