gpt4 book ai didi

php - mod_rewrite 的简单通配符?

转载 作者:行者123 更新时间:2023-11-28 05:01:24 24 4
gpt4 key购买 nike

mod_rewrite 的新手。我只是想做这样的事情:

# Turn on the rewriting engine
RewriteEngine On

# use item php page to show the item
RewriteRule ^parts/./[.]$ parts/item.php?id=$1 [NC]

所以当一个人输入 example.com/parts/anything/anything 时,URL 将转到

example.com/parts/item.php?id=the2ndanything

据我了解,句点表示任何字符。另外,我尝试在句点后添加一个 +(这应该意味着什么),但仍然没有用。

顺便说一句,我使用的是临时 URL,因为我还没有更改我以前的虚拟主机,因此我的实际完整 URL 中有一个 ~。我希望这不是 mod_rewriting 的问题,因此是阻止它工作的问题。 .htaccess 文件位于网站 index.html 的根文件夹中。

最佳答案

. 确实表示任何字符,但您必须在其后跟+(一个或多个)或*(零个或多个),您必须在 () 中捕获它以用作 $1。使用 [^/]+ 匹配所有字符,但不包括 / 匹配但不捕获 parts/ 之后的第一个目录。

RewriteEngine On
# (.*) captures the second "anything" in $1
RewriteRule ^parts/[^/]+/(.*)$ parts/item.php?id=$1 [L]

关于php - mod_rewrite 的简单通配符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14492822/

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