我的 url 看起來像:http://localhost/event_manage?slug=hello最后一個值就像這樣所以當我去的時候hello
那個頁面就在里面并顯示錯誤,因為沒有名為的檔案夾。但我希望這就像我去的時候獲得價值index.phphttp://localhost/event_manage/hellohellohellohttp://localhost/event_manage/hello
.htaccess我在檔案中試過:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-] )/$ index.php?slug=$1
但它仍然顯示錯誤并且無法傳遞值!
uj5u.com熱心網友回復:
RewriteRule ^([a-zA-Z0-9_-] )/$ index.php?slug=$1但錯誤是
http://localhost/event_manage/hello
上述規則假定您的 URL 以斜杠結尾,但您的示例沒有,因此它將無法匹配并導致 404(因為它沒有將請求重寫為index.php)。
它應該是:
RewriteRule ^([\w-] )$ index.php?slug=$1 [L]
\w(word characters) 只是一個速記字符類,與[a-zA-Z0-9_].
L如果您添加更多指令,則需要該標志。
這假定.htaccess并index.php位于/event_manage子目錄內。
在旁邊:
http://localhost/event_manage?slug=hello
因為/event_manage是一個物理目錄,所以這個 URL 應該是http://localhost/event_manage/?slug=hello(在目錄名后面有一個斜杠)。如果您省略尾部斜杠,則 mod_dir 將在尾部斜杠后面附加 301 重定向。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/487733.html
