There are cases when you want to change page URLs or disable some page and avoid 404 error. For this, you need to create 301 redirects.
In order to add 301 redirect in Magento 2 take the following steps:
1. Go to Admin Panel > Marketing > SEO& Search > URL Rewrites.
2. Then press the Add URL Rewrite button.
3. Enter URL Rewrite Information
- Choose "Custom" in Create URL Rewrite select box.
- Choose the store view you want the URL Rewrite to be added to in the Store field.
- Set the path you want to be redirected in the Request Path field.
- In the Target Path, you correspondingly set the path you want the old one to be redirected to.
- Choose Permanent(301) in the Redirect Type field.
- Enter short information why you add this rewrite in the Description text box (optional).
Attention! Do not enter either domain or store view code in the request and target paths.
4. Once you have finished creating the redirect don't forget to save it by pressing the Save button.
Sometimes you may face the unexpected 301 or 302 redirects in your Magento 2 caused by some code. To find out the reasons for it to appear you need to debug 301/302 redirects in Magento 2.