[英]Caching with Apache Mod Redirect
所以我想將所有緩存的頁面保存在名為/ cache的文件夾中
我在想擁有通用網址
example.com/not a real folder
靜默地重定向到
example.com/cache/not-a-real-folder.html
如果上述文件不存在,請將其重定向到
index.php?page=not a real folder
但是我如何設計將完成所有這些工作的Apache Mod Rewrite代碼,甚至有可能嗎?
我剛接觸這些東西,因此不勝感激! 非常感謝!
# First check if the file requested exists in the cache folder,
# if it does, rewrite the url to the cached version
# -The %{REQUEST_URI} will probably start with a '/'
RewriteCond /cache%{REQUEST_URI} -f
RewriteRule (.*) /cache$1.html [L,NC]
# If the request makes it here, the file requested is not in the cache,
# so we can rewrite the request to the index.php page for processing
RewriteRule (.*) /index.php?page=$1 [L]
為了清晰起見,您的請求是否帶有空格,是否需要用破折號重寫? 因為那增加了更多的復雜性...
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.