htaccess的 - 301重定向删除URL的一部分 [英] htaccess - 301 redirect removing part of url

查看:187
本文介绍了htaccess的 - 301重定向删除URL的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能去上班这301重定向,我必须从所有的请求去掉测试版字样,并重定向:
FROM: http://www.example.com/BeTa/other/content 至: http://www.example.com/other/content

I'm not able to get to work this 301 redirect, i have to remove "BeTa" word from all the request, and redirect:
FROM: http://www.example.com/BeTa/other/content TO: http://www.example.com/other/content

测试版也有可能是present url中的另一部分:
FROM: http://www.example.com/bla/BeTa/other/content 至: http://www.example.com/bla/other/content

"BeTa" could also be present in other part of url:
FROM: http://www.example.com/bla/BeTa/other/content TO: http://www.example.com/bla/other/content

这可能吗? 现在,我只尝试了第一部分:

is it possible? Right now I have only tried the first part:

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

在此先感谢

推荐答案

您可以调整你的正则表达式匹配巴塔的任何地方像这样的:

You can tweak your regex to match BaTa anywhere like this:

RewriteEngine on
RewriteRule ^(.+?/)?BeTa(?:/(.*))?$ /$1$2 [NC,R=301,L]

这篇关于htaccess的 - 301重定向删除URL的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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