基于URL到一个新的页面的RewriteCond重写规则进行的.htaccess,定期EX pression [英] RewriteCond RewriteRule for .htaccess based on URL to a new page, regular expression

查看:144
本文介绍了基于URL到一个新的页面的RewriteCond重写规则进行的.htaccess,定期EX pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有趣的重写规则,我不知道做正规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.

它归纳到这两个规则:

  1. 如果重定向后的第二/字符串包含任何信件
  2. 重定向如果字符串之后第二个/长于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.

这篇关于基于URL到一个新的页面的RewriteCond重写规则进行的.htaccess,定期EX pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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