In this article, you will be learning how to add 301 and 302 redirects in Drupal. The 301 redirect lets search engines know that the page is removed permanently, while the 302 lets them know the page is removed temporarily. Both of them send the user and search engine to a different URL.
The only pre-requisite for this is that you must have admin rights.
First, we need to install the redirect module.
Installing Redirect Module
- Start by clicking on Extend and then on + Install new module.
- Paste this URL in the box: https://ftp.drupal.org/files/projects/redirect-8.x-1.5.tar.gz. Proceed by clicking on Install.
- After the module installs you will see this message. Proceed by clicking on Enable newly added modules.
- Search for redirect in the search box. Check the box beside Redirect and click on Install.
- You will have successfully installed the Redirect module.
Adding 301 and 302 redirects
- Go to Configuration and proceed by clicking on URL redirects under Search And Metadata.
- Click on + Add redirect.
- Enter your old URL in the Path box, and the new URL in the To box. Select either 301 or 302 redirect from the Redirect status drop-down menu. We are choosing 301.
- Proceed by clicking on Save.
- Your redirect will be saved.
- Now search for your-site/old-url, but replace your-site with the name of your website. You will be redirected to the newly set URL.