使用以下方法从URL中删除目录 [英] Remove directory from URL with

查看:46
本文介绍了使用以下方法从URL中删除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这是为了使人们通过旧的URL进入网站时不会出现404错误.

This is so that people don't end up with a 404 error when they enter the site via an old URL.

推荐答案

尝试将其添加到文档根目录下的htaccess文件中,最好在您可能已经拥有的所有规则之上:

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]

如果要重定向浏览器,以便新的URL出现在位置栏中,请在方括号中添加R标志:

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]

这篇关于使用以下方法从URL中删除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆