Remove directory from URL using

I am moving the Magento website from example.com/shopping to example.com, and I need to redirect all the URLs to the new location 301 (example.com). I assume I can use mod_rewrite in the .htaccess file to create a rewrite rule for this? I tried to learn how to use mod_rewrite, but the syntax is so complicated for me.

There are hundreds of pages to redirect. Example:

http://www.example.com/shopping/product-category-1/product-sub-category.html 

TO

 http://www.example.com/product-category-1/product-sub-category.html 

This means that people don’t get a 404 error when entering the site through the old URL.

+6
source share
1 answer

Try adding this to the htaccess file at the root of your document, preferably above any rules that you may already have:

 RewriteEngine On RewriteRule ^shopping/(.*)$ /$1 [L] 

If you want to redirect the browser so that the new URL appears in the location bar, add the R flag in square brackets:

 RewriteEngine On RewriteRule ^shopping/(.*)$ /$1 [L,R=301] 
+8
source

Source: https://habr.com/ru/post/953366/


All Articles