我目前正在一個靜態網站上作業,我需要在某些頁面上將最后一個 URI 元素作為查詢引數傳遞。
我所有的靜態 html 頁面都在/pages/**/*目錄中,其中的路徑與最終網站上的所需路徑直接相關。/products/kitchen需要顯示含義/pages/products/kitchen.html。如果在此示例中該檔案/pages/products/kitchen.html不存在,我想嘗試將其作為名為( )的查詢引數/pages/products.html傳遞。目錄中有靜態資產,因此根本不應該將存在的檔案重寫到目錄中。如果沒有請求的路徑,我想重定向到默認主頁。該規則是針對 Kubernetes 集群中的活力檢查的,我只是將其保留在那里,因為我不能 100% 確定它不是罪魁禍首。kitchenid?id=kitchen/assets/pagesprobe.json
我試圖以某種方式將多個RewriteConds 和RewriteRules 鏈接在一起if > else if > else if > else,但這似乎在某些時候失敗了。不幸的是,這些錯誤很難除錯,因為除了 browsers 404-error 之外沒有任何跡象表明正在發生什么。目前,只有現有檔案和默認頁面的規則才能正常作業。對我做錯的任何幫助將不勝感激!
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .? - [L]
<files probe.json>
order allow,deny
allow from all
</files>
RewriteCond pages/$1.html -f
RewriteRule ^(.*)$ pages/$1.html [NC,L]
RewriteCond pages/$1.html -f
RewriteRule ^(.*(?=[/]))/(.*)$ pages/$1.html?id=$2 [NC,L]
RewriteRule ^$ pages/home.html [L]
uj5u.com熱心網友回復:
我找到了解決這個問題的方法。
我不得不使用絕對路徑。
我不得不
%{DOCUMENT_ROOT}在條件前面加上。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .? - [L]
<files probe.json>
order allow,deny
allow from all
</files>
RewriteCond %{DOCUMENT_ROOT}/pages/$1.html -f
RewriteRule ^(.*)$ /pages/$1.html [NC,L]
RewriteCond %{DOCUMENT_ROOT}/pages/$1.html -f
RewriteRule ^(.*(?=[/]))/(.*)$ /pages/$1.html?id=$2 [NC,L]
RewriteRule ^$ /pages/home.html [L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/467179.html
上一篇:映射請求以顯示子檔案夾中的內容
