开发者

Caching with Apache Mod Redirect

开发者 https://www.devze.com 2023-02-20 22:37 出处:网络
So I want to keep all my cached pages in a folder called /cache and I was thinking to have the generic url

So I want to keep all my cached pages in a folder called /cache

and I was thinking to have the generic url

example.com/not a real folder

silently redirect to

example.com/cache/not-a-real-fo开发者_如何学Pythonlder.html

and if the above file does not exist have it redirect to

index.php?page=not a real folder 

but how do I design the Apache Mod Rewrite code that will do all this, is it even possible?

I'm new to these things so any help would be greatly appreciated! Thank you so much!


# 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]

For clairification, are your requests coming in with spaces, and you need them rewritten with dashes? Because that adds some more complexity...

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消