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

パスの 2 番目の動的部分 (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 に答える