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.
- 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".
- Export an SQL dump that has the DROP TABLES IF EXISTS and CREATE TABLES commands for the MySQL tables that runs the WordPress site.
- 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.
- 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").
- Next replace all instances of "www.karavadra.net" with "karavadra.net". This will remove the "www." part in links within content.
- 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).
- 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.