1

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 的根文件夹中。

4

1 回答 1

6

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

RewriteEngine On
# (.*) captures the second "anything" in $1
RewriteRule ^parts/[^/]+/(.*)$ parts/item.php?id=$1 [L]
于 2013-01-24T02:18:39.047 回答