Would you like to learn how to redirect a URL on Apache? In this tutorial, we are going to show you how to install the Apache server and create a rule to redirect a URL on a computer running Linux.
• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Apache 2.4.41
In our example, the Apache server is hosting the website WWW.GAMEKING.TIPS.
Copyright © 2018-2021 by Techexpert.tips.
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means without the prior written permission of the publisher.
Equipment list
The following section presents the list of equipment used to create this tutorial.
As an Amazon Associate, I earn from qualifying purchases.
Apache – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Apache.
Tutorial Apache – URL redirection
Install the Apache server.
Enable the required Apache modules.
Edit the Apache configuration file for the desired website.
Add the following lines to this configuration file.
Use 301 for permanent redirection and 302 for temporary redirection.
Change this line to reflect your needs.
Here is the file, before our configuration.
Here is the file, after our configuration.
Restart the Apache service.
In our example, the Apache server will redirect the test URL to the Google website.
From a remote Linux computer, try to access the redirected URL.
Here is the command output.
The Apache server will redirect the test URL to the Google website.
Tutorial Apache – URL redirection using MOD_REWRITE
Install the Apache server.
Enable the required Apache modules.
Edit the Apache configuration file for the desired website.
Add the following lines to this configuration file.
Use 301 for permanent redirection and 302 for temporary redirection.
Change this line to reflect your needs.
Here is the file, before our configuration.
Here is the file, after our configuration.
Restart the Apache service.
In our example, the Apache server will redirect the test URL to the Google website.
From a remote Linux computer, try to access the redirected URL.
Here is the command output.
The Apache server will redirect the test URL to the Google website.
Tutorial Apache – URL redirection using HTACCESS
Install the Apache server.
Enable the required Apache modules.
Edit the Apache configuration file.
Add the following lines at the end of the file.
Create an HTACCESS file on the website directory.
Add the following lines to this configuration file.
Use 301 for permanent redirection and 302 for temporary redirection.
Change this line to reflect your needs.
There are multiple ways to perform the URL redirection.
Optionally, use the following configuration.
Configure the correct file permission.
Restart the Apache service.
In our example, the Apache server will redirect the test URL to the Google website.
From a remote Linux computer, try to access the redirected URL.
Here is the command output.
The Apache server will redirect the test URL to the Google website.