简体   繁体   English

从URL中删除目录

[英]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). 我正在将一个Magento站点从example.com/shopping移动到example.com,我必须将所有URL重定向到新位置(example.com)。 I am assuming I can use mod_rewrite in the .htaccess file to create a rewrite rule to do this? 我假设我可以在.htaccess文件中使用mod_rewrite创建一个重写规则来执行此操作? I tried to learn how to use mod_rewrite, but the syntax is so complex for me. 我试着学习如何使用mod_rewrite,但语法对我来说太复杂了。

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. 这样,人们在通过旧URL进入网站时不会出现404错误。

Try adding this to the htaccess file in your document root, preferably above any rules you may already have there: 尝试将其添加到文档根目录中的htaccess文件中,最好是您可能已经拥有的任何规则:

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: 如果要重定向浏览器以便新URL显示在位置栏中,请在方括号中添加R标志:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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