简体   繁体   中英

Remove directory from URL with

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

There are hundreds of pages that need to be redirected. 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 is so that people don't end up with a 404 error when they enter the site via an old URL.

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM