新的修改。我只想做这样的东西:
# 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=2ndanything
据我所知,这个时期意味着任何一种性格。另外,我试着在句号后加上一个+号(这应该和任何东西一样重要),但仍然没有起作用。
顺便说一下,我使用的是一个临时URL,因为我还没有更改以前的web主机,因此我的实际完整URL中有一个~符号。我希望这不是一个修改的问题,因此是阻止它工作的问题。.htaccess文件位于web站点index.html的根文件夹中。
最佳答案
.
指的是任何字符,但您必须按照+
(一个或多个)或*
(零个或多个)执行,并且必须在()
中捕获它,才能用作$1
。使用[^/]+
匹配/
之前但不包括parts/
的所有字符,以匹配但不捕获之后的第一个目录。
RewriteEngine On
# (.*) captures the second "anything" in $1
RewriteRule ^parts/[^/]+/(.*)$ parts/item.php?id=$1 [L]