Magento – How to change product URL and redirect

base-urlmagento2urlurl-rewrite

Here's the situation I need to redirect one of my product to homepage make it as homepage at the same time the URL must be changed to home, so instead of www.example.com/sample-product it should be www.example.com take note that I am accessing this link www.example.com/sample-product.

I am also confused if I'm going to use the rewritten URL.

What would be the best approach?

Best Answer

You can just use the rewrite where request path is sample-product and the target path is ../. Anyone visiting the URL www.domain.com/sample-product will end up at www.domain.com. The default homepage will also need to be set to your product.

  1. Navigate to Marketing -> SEO & Search -> URL Rewrites

Find the Magento path of the Product URL by looking within the Rewrite table. I typed in URL of product you want to be your homepage in target path and found request path for that particular product.

e.g. catalog/product/view/id/1

Make a note of this URL.

  1. Navigate to Stores -> Configuration -> General -> Web -> Default Pages

Set the Default Web URL to your product e.g. catalog/product/view/id/1

Accessing www.domain.com will now show your product.

  1. Navigate to Marketing -> SEO & Search -> URL Rewrites -> Add URL Rewrite

a. Set Request Path: sample-product

b. Set Target Path: ../

c. Set Redirect Type: Permanent

This sets your product URL so that it will be redirected to the homepage also.