我想使用 .htaccess 來重寫這樣的 URL
https://example.com/pages/games/demons-souls/?page=mods
看起來像這樣
https://example.com/games/demons-souls/mods
我設法使用以下代碼隱藏 URL 中的 pages 檔案夾:
Options MultiViews
RewriteEngine On
# Rewrite "/games/<anything>" to "/pages/games/<anything>"
RewriteCond %{REQUEST_URI} !^/pages/games
RewriteRule ^games($|/.*) pages/$0
但我需要一個適當的 RewriteRule 用于查詢字串。我試過這個,但它沒有用......
RewriteRule ^([^/]*)/([^/]*)$ $1/index.php?page=$2 [L,QSA]
我真的很感激一些幫助。
uj5u.com熱心網友回復:
你可以這樣:
Options MultiViews
RewriteEngine On
# Rewrite "/games/<foo>/<bar>" to "/pages/games/<foo>/?page=<bar>"
RewriteRule ^(games/[\w-] )/([\w-] )/?$ pages/$1/?page=$2 [L,NC,QSA]
# Rewrite "/games/<anything>" to "/pages/games/<anything>"
RewriteRule ^games($|/.*) pages/$0 [L,NC]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/441222.html
上一篇:如果應用程式android的檔案中不存在檔案夾,如何創建檔案夾
下一篇:阻止以數字開頭的網站頁面
