[英]mod_rewrite rule using date regex
I'm trying to write a rule that when user types in this url: 我正在尝试编写一条规则,当用户键入此url时:
domain.com/09/13/2013/thisIsMyPageTitle
That url stays in browser window, but content from this url is displayed: 该URL保留在浏览器窗口中,但显示该URL的内容:
domain.com/contentlibrary/thisIsMyPageTitle
This is my rule that I currently get an error with: 这是我目前遇到以下错误的规则:
RewriteEngine On
RewriteRule ^((0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d[/])$(.*) /contentlibrary/$1 [L]
I'm trying to match the date with regular expression, and use the (.*) from the initial url in the second one that holds the content and actually exists. 我正在尝试将日期与正则表达式匹配,并使用第二个包含内容并实际存在的初始URL中的(。*)。
If you're not going to do anything with date then why bother being precise with date semantics. 如果您不打算对日期做任何事情,那为什么还要麻烦日期语义呢。 You can simplify your regex:
您可以简化正则表达式:
RewriteRule ^[0-9]+/[0-9]+/[0-9]+/([^/]+)/?$ /contentlibrary/$1 [L]
The error that you're getting is probably because you have unescaped spaces in your regex. 您收到的错误可能是因为您的正则表达式中有未转义的空格。 Specifically these:
特别是这些:
[- /.]
The spaces get interpreted by mod_rewrite as the delimiter between parameters. 空格由mod_rewrite解释为参数之间的分隔符。 Additionally, you have this:
此外,您有:
$(.*)
at the end of your pattern. 在图案的结尾。 The
$
matches the end of the string , so you want those swapped: $
与字符串的末尾匹配,因此您希望将它们交换:
(.*)$
So: 所以:
^((0[1-9]|1[012])[-\ /.](0[1-9]|[12][0-9]|3[01])[-\ /.](19|20)\d\d[/])(.*)$
shold be the pattern that you want. 保持您想要的模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.