繁体   English   中英

mod_rewrite的简单通配符?

[英]Simple wild character for mod_rewrite?

是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

根据我的理解,句号表示任何字符。 另外,我尝试在句号后添加一个+(这应该意味着尽可能多的意思),但这仍然没有用。

顺便说一句,由于我尚未更改以前的Web主机,因此我使用的是临时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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM