我是編碼新手,因此將不勝感激額外的解釋。到目前為止,我能夠使用我的 htaccess 文件刪除文件擴展名。Options -MultiViewsRewriteEngine on# Does not apply to existing directories, if directory exist then don't run the ruleRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}\.php -fRewriteRule ^(.*)$ $1.php [NC,L]在“儀表板”目錄中,我有另一個 index.php(僅對登錄的用戶顯示)。在索引中,我有一個 $_GET 方法來檢索用戶的狀態。因此,當我訪問 localhost/project/dashboard/ 時,我可以查看 index.php。當我想使用 GET 方法時,我的 url 將類似于 localhost/project/dashboard/?status=active,我試圖將其更改為 localhost/project/dashboard/active 或 localhost/project/dashboard/status/active。我在本地主機環境中工作,我的目錄是這樣分解的。MAIN- includes- dashboard|-- subfolder|-- somefile.php|-- index.php- cssindex.phplogin.phplogout.php.htaccess ** (this is the file im working with)我正在使用 URL:http://localhost/project/dashboard/active我嘗試將以下幾行添加到我的 .htaccess1.RewriteRule ^([a-zA-Z]+)/?$ /?status=$1 [NC,L,QSA] - doesn't work未找到對象!錯誤 4042.RewriteRule ^dashboard/([a-zA-Z]+)/?$ /?status=$1 [NC,L,QSA] - doesn't work重定向到本地主機/儀表板3.如果我在“儀表板”目錄中創建另一個 .htaccess 并使用 write 1 lineRewriteRule ^([a-zA-Z]+)/?$ index.php?status=$1 [NC,L,QSA] - WORKS但是,當使用第三種方法時,我無法訪問儀表板中的子文件夾或其文件。因此,如果我嘗試訪問 localhost/project/dashboard/subfolder/somefile,它會返回“找不到對象!” 錯誤 404如果我嘗試訪問 localhost/project/dashboard/subfolder/somefile.php 它會重定向到 localhost/project/dashboard/以后會有更多的文件夾和子文件夾。
帶有 $_GET 方法的漂亮 URL
幕布斯6054654
2021-11-26 16:29:49
