301 Redirection in Joomla

Have you ever found out that your page was published at the wrong address? You have been too quick and published a page in the wrong category, or used words in your alias that is not related to the topic. There are many occasions and reasons when you can decide to change the location of your page. The reason will most likely be better on-page SEO or changing a link to something that more memorable. This guide will teach you how to make this safely in Joomla.

Before you change the link to your page, you should make a proper redirection to the new location. Therefore, you will tell search engines that your page is still existing, but on a new address. Also, if some of your visitors bookmarked this page, they will be able to visit it normally even after the link update.

301 redirections are permanent. By using this type of redirection, we are instructing the search engines that our page has changed its location permanently (forever). On 99% of occasions, that's what you need.

Requirements

We suppose that you are running your Joomla on Apache or Litespeed web server. One of these web servers is used on most of the available hosting providers. Another relatively popular web server is NGINX, but it will not be covered here.

Where to add the 301 redirections?

The easiest way to add and control your 301 redirections is to edit the ".htaccess" file. This file comes with every Joomla installation, but it's not activated by default. Actually, it's named "htaccess.txt" and in order to activate it, you need to rename it to ".htaccess". In the UNIX world, if a file starts with a dot, it's a hidden file. If you are using cPanel's File Manager, to see the hidden files, you must enable this option first. You can see the hidden files in FTP unless it's disabled in the FTP client settings.

If you enabled "Search Engine Friendly URLs" and "Use URL Rewriting" in the Global Configuration of Joomla, then you already have an active ".htaccess" file. Also, even if you did not enable it, it's possible that the ".htaccess" file is already present in your Joomla root folder (for example, it might be created by your hosting provider).

So, if there's a ".htaccess" file in your Joomla root, just edit it. Don't delete it! If there's no such file present (and you can see the hidden files), rename the Joomla file "htaccess.txt" to ".htaccess".

Edit the ".htaccess" file

You can edit this file from the control panel of your hosting (if it allows you), or you can download it to your computer via FTP and then edit it with the code editor. You can also use Notepad on Windows or Textedit on Mac to edit this file.

At the end of this file (after everything else), you can add your redirections. Add them in this format:

redirect 301 /my-old-location https://www.mycoolsite.com/my-new-location

This is the command to the server to create a redirection of type 301. This command should have 2 parameters:

  1. The first parameter (in our case "/my-old-location") is the location of your old page, without the domain of your website. So, in this example, your page's old location was "https://www.mycoolsite.com/my-old-location". The domain is not included here because it's clear that we are redirecting FROM the current domain.
  2. The second parameter (in our case "https://www.mycoolsite.com/my-new-location") is the new location of your page, including the domain. The domain is included here because we can redirect our page TO any domain we want, including our current domain.

When you finished the file edits, save it on the server, or upload using an FTP client. Some web hosting providers use caching of files intensively, so you might need to wait a few minutes until the new ".htaccess" file becomes active.

Testing the redirection

When the new ".htaccess" file is active in the root folder of Joomla, you are ready to test it. Try to open the old location of your page (for example "https://www.mycoolsite.com/my-old-location") and see the output. If your redirection is active, you will be immediately redirected to the new location (for example "https://www.mycoolsite.com/my-new-location"). If you are getting a 404 error, then it's not working.

This redirection will also instruct the search engine spiders about the new location of your page. Search engines will update their databases after a period of time. Even until the old location is displayed on the search engine result page, you won't lose any traffic. The redirection will redirect the visitors to the new location automatically.