gpt4 book ai didi

php - 在 mod 重写中忽略动态路径并保留子路径

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:46:05 27 4
gpt4 key购买 nike

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

动态路径的几个例子:

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) 是处理真实查询字符串的真实 ID:

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)???

谢谢。

最佳答案

像这样的东西应该有用...

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

关于php - 在 mod 重写中忽略动态路径并保留子路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15144118/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com