Regex 如果请求URI中有x个字符,则重写COND

Regex 如果请求URI中有x个字符,则重写COND,regex,mod-rewrite,apache2,Regex,Mod Rewrite,Apache2,这可能是一个简单的答案,但我很难弄明白这一点 假设我有以下urlhttp://www.somewhere.com/ENGESV/somepath/index.html 我正在尝试匹配RewriteCond如果URL路径的开头有大写或小写,则0-9和6个字符(例如/ENGESV/)将符合我的条件 我试过下面的几种替代方法,但没有成功 RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.somewhere.com)$ [NC] RewriteCond %{

这可能是一个简单的答案,但我很难弄明白这一点

假设我有以下url
http://www.somewhere.com/ENGESV/somepath/index.html

我正在尝试匹配
RewriteCond
如果URL路径的开头有大写或小写,则0-9和6个字符(例如
/ENGESV/
)将符合我的条件

我试过下面的几种替代方法,但没有成功

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.somewhere.com)$ [NC]
RewriteCond %{REQUEST_URI} ^\/([0-9a-zA-Z]{6})\/(.*)$
RewriteRule .* http://www.somewhereelse.com%{REQUEST_URI} [R=301,L]

你的正则表达式看起来不错,尽管你不需要捕获组。见:

您是否启用了“重写”模块

sudo a2enmod重写