[英]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.