我有一个包含动态路径的网站,我需要知道如何保留部分或忽略它:
动态路径的几个例子:
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)???
感谢。
答案 0 :(得分: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) «$»