0

我有一个带有动态路径的站点,我需要知道如何保留或忽略它:

动态路径的几个示例:

http://www.example.com/185/seo-dynamic-field.html
http://www.example.com/186/seo-dynamic-field2.html

如您所见,seo-dynamic-field.html 是从 mysql 生成的字段,仅用于友好的 url。id ( 185& 186) 是处理真实查询字符串的真实字符串,即:

RewriteRule ^/*(([^/]+)(.html))$ index.php?id=$2 [L]

这是有效的:

http://www.example.com/186.html

但我想做的是以下内容:

http://www.example.com/186/seo-field.html

有没有办法忽略路径的第二个动态部分(seo-field1.html,seo-field2.html)???

谢谢。

4

1 回答 1

0

像这样的东西应该工作......

RewriteRule ^/?(\d+)/?.*\.html$ index.php?id=$1 [L]

这是解释的正则表达式...

^/?(\d+)/?.*\.html$
Assert position at the beginning of the string «^»
Match the character “/” literally «/?»
   Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match the regular expression below and capture its match into backreference number 1 «(\d+)»
   Match a single digit 0..9 «\d+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “/” literally «/?»
   Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match any single character «.*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the character “.” literally «\.»
Match the characters “html” literally «html»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»
于 2013-02-28T19:43:04.230 回答