Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 310
peterbujok Avatar asked Sep 07 '13 00:09

peterbujok


1 Answers

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]
like image 120
Jon Lin Avatar answered Nov 09 '22 13:11

Jon Lin