基于URL到一个新的页面的RewriteCond重写规则进行的.htaccess,定期EX pression重写、规则、页面、RewriteCond

2023-09-02 10:10:39 作者:晑脕铷謌

我有一个有趣的重写规则,我不知道做正规EX pression。

I have an interesting RewriteRule and I am not sure to make the regular expression.

总之,我想检查后的URL中的第二个/ - 基于内容的,可能是前进

In short I would like to examine the URL after the second / - based on the contents, possibly forward.

它归纳到这两个规则:

如果重定向后的第二/字符串包含任何信件 重定向如果字符串之后第二个/长于7个字符

下面举例说明:

http://www.mysite.org/section/subsection/2011 ( OK,什么都不做)

http://www.mysite.org/section/subsection/2011 (OK, do nothing)

http://www.mysite.org/section/subsection/2011-11 (好吧,什么都不做)

http://www.mysite.org/section/subsection/2011-11 (OK, do nothing)

http://www.mysite.org/section/subsection/2011- 11-09 (也不行,重定向)

http://www.mysite.org/section/subsection/2011- 11-W1 (也不行,重定向)

请帮我重写规则和重写电导率

Please help me with the Rewrite Rule and Rewrite Cond

推荐答案

我基于以下的正则表达式掉你的例子这似乎一切都进行分析后,最后一个'/',而不是第二。

I based the following regex off of your examples which seemed to analyze everything after the last '/' instead of the second.

/[^A-Za-z]{1,7}$

在简单的英语,这正则表达式匹配一组字符遵循一个/,其中包含1-7非字母字符。使它只匹配最后'/'我所附一个'$',其中行的末尾匹配。

In plain English, this regex matches a group of characters that follows a '/' and contains 1-7 non-alphabetical characters. To make it only match the last '/' I appended a '$', which matches the end of a line.

此外,由于你正在处理的URL,你可能要加上/?在$的情况下,之前有一个悬空'/'结尾。

Also, since you are dealing with URLs you might want to add "/?" before the '$' in case there is a dangling '/' at the end.

/[^A-Za-z]{1,7}/?$

我希望这回答了你的问题。

I hope this answers your question.