从URL中删除目录

时间:2013-09-07 00:55:12

标签: .htaccess magento redirect mod-rewrite

我正在将一个Magento网站从example.com/shopping移动到example.com,我必须将所有网址重定向到新位置(example.com)。我假设我可以在.htaccess文件中使用mod_rewrite创建一个重写规则来执行此操作?我试着学习如何使用mod_rewrite,但语法对我来说太复杂了。

有数百个页面需要重定向。例如:

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

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

这样,人们在通过旧网址进入网站时不会出现404错误。

1 个答案:

答案 0 :(得分:8)

尝试将此添加到文档根目录中的htaccess文件中,最好是您可能已经拥有的任何规则:

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

如果您想重定向浏览器以便新地址显示在位置栏中,请在方括号中添加R标记:

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