![]() |
VOOZH | about |
The redirects are one of the most important configurations that allow a web server to redirect traffic from one URL to another. This would help you forward visitors to a new location whenever content changes its location, or it will let you show multiple URLs under one canonical URL. In this article, we'll see how to add redirects in Apache—the
These are the following methods to add redirects:
Table of Content
Well, Apache provides several ways of setting up redirects based on your needs and server setup.
Redirect 301 /old-page.html http://www.example.com/new-page.htmlRedirect 302 /temporary-page.html http://www.example.com/new-temporary-page.htmlAdd Redirect Rule within the VirtualHost Block:
<VirtualHost *:80>
ServerName www.example.com
Redirect 301 /old-page.html http://www.example.com/new-page.html
</VirtualHost>
You can turn it on with the command:
sudo a2enmod rewriteAdd Rewrite Rules in .htaccess or Apache Config:
RewriteEngine On
RewriteRule ^old-page\.html$ http://www.example.com/new-page.html [R=301,L]
Setting up redirects in Apache is one of the fundamental skills to run the traffic on a website. Be it condensing pages, handling moved content, or optimizing the site for search engines; proper use of redirects guarantees that both users and search engines could always find your content. Now, by following these steps, you can go about confidently using the different methods that Apache provides to implement redirects.