在URL替换目录名称与另一个名称 [英] Replace directory name in url with another name

查看:242
本文介绍了在URL替换目录名称与另一个名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用htaccess的,我怎么可以改变URL的http://www.website.com/abc / ...到HTTP://www.website.com/xyz / ...所以它的行为因为它的ABC之后做了之后XYZ重定向到相同的文件名/目录结构。

解决方案

 重写规则^ ABC /(.*)$ / XYZ / $ 1 [R = 302,L,QSA]
 

这将重定向 example.com/abc/pink-kitten example.com/xyz/pink-kitten (或 example.com/abc / example.com/xyz / ),但如果尾随不会做任何事情斜线的文件夹名称后失踪(即 example.com/abc 将不被重定向)。如果你需要的最后一种情况以及那么你将需要使用不同的规则这一点。

您可以更改重定向code [R = 302] 到另一个如果需要的话(例如301永久重定向)。

Using htaccess, how can I change the url "http://www.website.com/abc/..." to "http://www.website.com/xyz/..." so it acts as a redirect to the same filename/directory structure after "xyz" as it did after "abc".

解决方案

RewriteRule ^abc/(.*)$ /xyz/$1 [R=302,L,QSA]

This will redirect example.com/abc/pink-kitten to example.com/xyz/pink-kitten (or example.com/abc/ to example.com/xyz/) but will not do anything if trailing slash after the folder name is missing (i.e. example.com/abc will not be redirected). If you need the last case as well then you will need to use separate rule for that.

You can change redirect code [R=302] to another if required (e.g. 301 Permanent Redirect).

这篇关于在URL替换目录名称与另一个名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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