0

我正在尝试编写一个规则,当用户输入此 url 时:

domain.com/09/13/2013/thisIsMyPageTitle

该 url 保留在浏览器窗口中,但显示来自该 url 的内容:

domain.com/contentlibrary/thisIsMyPageTitle

这是我目前遇到错误的规则:

RewriteEngine On
RewriteRule ^((0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d[/])$(.*) /contentlibrary/$1  [L]

我正在尝试将日期与正则表达式匹配,并使用第二个包含内容且实际存在的初始 url 中的 (.*)。

4

2 回答 2

3

如果您不打算对日期做任何事情,那么为什么还要对日期语义进行精确处理。您可以简化您的正则表达式:

RewriteRule ^[0-9]+/[0-9]+/[0-9]+/([^/]+)/?$ /contentlibrary/$1 [L]
于 2013-09-18T19:02:21.800 回答
0

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. 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.

于 2013-09-18T19:13:08.467 回答