How to Remove www from Your Joomla Website URLs

For one reason or the other, you might decide to remove the www part from the URLs of your Joomla website. It might be that you have a short domain and you may want to emphasize the shortness of the domain even more, or it might be that you just don’t like seeing www in your URLs. Some people mistakenly think that removing (or having) www will favorably affect their SEO standings – this is a myth. However, having consistent and non-redundant URLs by removing (or adding) www from all your URLs will certainly help your SEO. This is because of 2 things:

  • A consistent website will look more professional from a search engine perspective.
  • There will be no non-intended duplicate content on your website (for example, http://www.yourjoomlawebsite/article-1 and http://yourjoomlawebsite.com/article-1 are considered to be duplicate content – although this duplicate content is soft, and is usually not punished by search engines).

Now, how to remove www from your Joomla website URLs?

There are two ways to do this: one by modifying your .htaccess file and another by modifying your index.php file. We recommend modifying your .htaccess file because it’s easier and more efficient and because you won’t have to fiddle Joomla’s core code. Only go for the latter option (index.php) if you don’t have access to your .htaccess file.

  • Removing www using .htaccess

    Simply add the following code to the beginning of your .htaccess file1:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.yourjoomlawebsite.com
    RewriteRule (.*) http://yourjoomlawebsite.com/$1 [R=301,L]

    (Note: we have discussed redirecting non-www to www before in our article about handling duplicate content on your Joomla website.)

    Once you add the above lines, save the file, and upload it to your root directory. Try going to http://www.yourjoomlawebsite.com/article-1, you will notice that you are automatically redirected to http://yourjoomlawebsite.com/article-1.

  • Removing www by modifying your index.php file

    As stated earlier, you should only modify your index.php if you’re unable, for some (mysterious) reason, to modify your .htaccess file, this is because you will be modifying a core Joomla file, which means that your edits might be wiped out (or affected) by future upgrades.

    In any case, to remove www from your Joomla website URLs, you should add the following code at the beginning of your index.php:

    function redirectURLNoWWW() {
    	$currentURL = "";
    	($_SERVER["HTTPS"] == "on")? $currentURL = 'https://' : $currentURL = 'http://';
    	$currentURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    	$currentURLNoWWW = str_replace("http://www.", "http://", $currentURL);
    	$currentURLNoWWW = str_replace("https://www.", "https://", $currentURL);
    	if ($currentURLNoWWW != $currentURL)
    		header("Location:".$currentURLNoWWW, TRUE, 301);
    }
    redirectURLNoWWW();
    

Note that there are many 3rd party plugins that will also do the redirection for you, but we just wanted to show you how to do this manually! Doing this manually is sometimes better (especially when doing it through the .htaccess file), because some 3rd party plugins may create conflicts with your website.

If you need help doing the above, then you have found the right place! Just contact us and we’ll take it from there! It usually takes us very little time to do the above and our fees are very reasonable!

1Please note that most GoDaddy servers (at the time of writing this post) do not load the new .htaccess file instantly – and sometimes it might take up to an hour for your .htaccess to take effect.

No comments yet.

Leave a comment