What are page redirects?
Simply put, page redirects are a way to forward users from one page to another. Not having to use them is the best scenario, but often they are needed.
There are multiple types of redirects. In this guide, we will focus on the two most popular ones:
A 301 redirect is used when you’re permanently moving your page to another URL. When using this type of redirect, search engines will remove the old page from their index.
A 302 redirect is used when you’re temporarily moving your page to another URL.
When to use redirects?
Redirects are used in various situations.
- You changed the URL but you have the old one linked from multiple external websites (301)
- You are moving your site to a new domain (301)
- You want to make sure that your page is only available under exactly one address (e.g. the non-www-version redirects to the www-version, the http-version redirects to the https-version, etc.) (301)
- You have multiple domains, but want to consolidate all content under a default one (301)
- You want to switch to a different URL scheme due to SEO reasons (301)
- Logged-in users should be redirected to a different page than non logged-in users (302)
For the rest of this guide, we will focus on 301 redirects as this is the most common and usually the recommended type of redirect.
How to redirect a page by using .htaccess?
Joomla websites usually come with a special file called .htaccess which lets you configure your web server’s behaviour. The .htaccess file can also be used to set up redirects. It is located in the root folder of your site. Joomla has a default one called htaccess.txt. You can just rename that one to be .htaccess, the official filetype for .htaccess-files, and modify it to your liking.
For an easy way to access your server, check our guide Accessing your Joomla directory with FTP
Let’s open the .htaccess file…
So this is what we want to achieve: When someone enters the old URL in their browser’s address bar, we want them to get redirected to the new URL.
redirect 301 /old-link.html http://www.site.com/new-link.html
Let’s get a bit more into the details:
- redirect 301 – Your link is going to use a permanent 301 redirect
- old-link.html – The link you plan on replacing
- http://www.site.com/new-link.html – The new link you want to be shown (has to be a complete URL)
This is the most basic way to set up a redirect, however you can also set up more complex redirect schemes with your .htaccess-file, which we won’t elaborate on here, because, as we’re using Joomla, thankfully there is a component that helps us with managing redirects without having to hard-code the .htaccess-file.
How to redirect a page using Joomla Redirect Manager?
As always, life is simpler if you’re using Joomla. In the standard Joomla installation, there is a component called Redirect Manager. You can access it from your Administrator by going to Components -> Redirects..
Before starting with redirecting pages with the Joomla redirect manager, you have to make sure that ‘Use URL Rewriting’ is enabled.
- Log into your Administrator
- Open System -> Global Configuration
- Under the Site tab, find Use URL Rewriting and enable it
Now, we can go back to the Redirect Manager and start with our first redirect. If you’re redirecting to another page from your site, make sure that you have a menu item that has an alias with the value of the new link.
- Go to Components -> Redirects
- Click on the button New
- Under Expired URL, type “/old_link”
- Under New URL, type “/new_link”
- If you want to redirect to an external URL, use absolute values (e.g. https://www.site.com/new_link)
- Save the new values
Congrats, you’ve set up your first redirect by using the Joomla redirect manager. Now each time someone opens the old URL, they will be redirected to the new one.