Website redirects and URL rewrite settings
You can manage a store’s redirects and rewrite settings by logging on to your Magento backend and navigating to :
- By default, Magento adds the .html extension to all URLs. It’s recommended to remove the .html extension to prevent potential issues further down the road, when switching to a different eCommerce platform.To remove the .html extension from the URLs, log on to your Magento backend and navigate to:
- in that same screen, you can choose whether or not to include the product-category key in a product’s URL, for example: https://example.com/category/product/.
- By default, Use Categories Path for Product URLs is set to No. Keep it that way to ensure that URLs stay short. This is especially important if you have categories with subcategories; URLs will become very long quickly. If you have products with highly similar names, it's recommended to include a unique identifier such as the SKU in a product's URL. Out of the box, you can't configure this in the Magento 2 backend
- In cases where URL keys change after pages have been published, you want to redirect visitors and search engines to the right URL when they request the old URL.
- By default, this is turned on: Create Permanent Redirect for URLs if URL Key Changed is set to Yes.
STEP 1:
Stores > Configuration (under Settings) > General > Web.
STEP 2:
Under Url Options you’ll find the field Add Store Code to Urls. Keep its value set to it’s default: No to make sure URLs are descriptive and easy to read.
STEP 3:
The field Auto-redirect to Base URL enables you to automatically redirect visitors and search engines when they request your store without the subdomain (e.g. when https://www.example.com is requested, clients are forwarded to https://example.com), or vice versa. While this is a great feature, by default it’s configured to use a temporary 302 redirect instead of a 301 redirect. Change this value to Yes (301 Moved Permanently) to make sure link authority from incorrectly placed links is passed on as much as possible to the right URL.
Remove the .html extension from product URLs and product-category URLs
STEP 1:
Stores > Configuration (under Settings) > Catalog > Catalog > Search Engine Optimization.
STEP 2:
In the screen that this loads, you'll find the fields Product URL Suffix and Category URL Suffix. Both fields have the value .html. Removing that value from both fields will lead to URLs such as https://example.com/category for category pages, and https://example.com/product for product pages. If you prefer to have a trailing slash at the end of all URLs, you can fill in / in both fields, leading to URLs like https://example.com/category/ and https://example.com/product/.