htaccess的 - 301重定向删除URL的一部分 [英] htaccess - 301 redirect removing part of 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屋!