2013-02-28 36 views
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)的第二动态部分???

谢谢。

+0

确定当前重写规则适用于你的第一种情况? ? – Shef 2013-02-28 19:38:45

+0

我刚刚纠正并从RewriteRule中删除了ID,以避免混淆人。有任何想法吗? – Uuid 2013-02-28 19:40:40

+0

刚给你答案! :) – Shef 2013-02-28 19:44:52

回答

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) «$» 
+1

很好的解释,它虽然崇拜像一个魅力。 – Uuid 2013-02-28 19:54:41