.htaccess重定向部分网址格式 [英] .htaccess redirect partial url pattern
问题描述
我在编写正确的重定向语句时遇到问题,很遗憾,我无法将所需的语法强加于人。其他问题也有类似的问题,但是我不知道如何正确地重用其他帖子中的信息。
I am having issues with writing the proper redirect statement, and unfortunately can't rap my head around the syntax needed. Other questions have similar problems, but I can't figure out how to properly reuse the information in other posts.
我有一个网址: www.site。 com /.../ CORE_Testing_5010 。
我需要页面重定向到 www.site.com/core-phase
... 可以是多个目录 / a / b / c / d / CORE_Testing_5010 或只是 / a / CORE_Testing_5010
The ... could be multiple directories /a/b/c/d/CORE_Testing_5010 or just /a/CORE_Testing_5010
现在,对于大多数可能的目录组合,我有310个重定向,但这效率很低。
Right now, I have 310 redirects for most of the possible directory combinations, but that is inefficient.
一些指导和解释会有所帮助。
Some guiedence and explanation would be helpful.
推荐答案
尝试:
RedirectMatch 301 /CORE_Testing_5010$ /core-phase
正则表达式模式忽略了最后一个 /
之前的所有内容,因此 /前面可以有任何内容CORE_Testing_5010
。
The regex pattern ignored everything before the last /
, so there can be anything in front of /CORE_Testing_5010
.
如果您有重写规则,并使用mod_alias( RedirectMatch
)导致冲突,那么您可以坚持使用mod_rewrite:
If you have rewrite rules, and using mod_alias (the RedirectMatch
) is causing conflicts, then you can stick with mod_rewrite:
RewriteRule /?CORE_Testing_5010$ /core-phase [L,R=301]
,它必须在任何进行路由的规则之前。
and it needs to be before any rules that do routing.
这篇关于.htaccess重定向部分网址格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!