【问题标题】:htaccess override requested uri exists in cache folderhtaccess 覆盖请求的 uri 存在于缓存文件夹中
【发布时间】:2014-08-22 06:05:16
【问题描述】:

我想检查用户是否请求任何页面,htaccess 检查缓存文件夹中的页面以及缓存页面是否存在。 htaccess 将其请求的页面重写到该缓存页面。

文件夹结构:

根/
产品/
服务/
缓存/
产品/index.html
服务/index.html
index.php
图片/
css/

例如:example.com/product/ 到 example.com/cache/product/

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{DOCUMENT_ROOT}/cache/$2/index.html -f [NC]
    RewriteRule ^(.+?)/?$ /cache/$1/index.html [L]
    
    RewriteCond %{DOCUMENT_ROOT}/cache/$1 -f [NC]
    RewriteRule ^(.+?)/?$ /cache/$1 [L]
    

    【讨论】:

    • 如果我输入 example.com/product/ 它说找不到 404,example.com/product/index.html 比它的工作。请帮帮我
    • 我会用这个脚本来处理动态文件,比如 minifyied js css
    • 确保这个 .htaccess 在DocumentRoot 中并且这条规则是你的第一条规则。还要确保$DOCUMENT_ROOT/cache/product/index.html 文件存在。
    • 文件在那里。并且 .htaccess 在根目录中
    • 非常非常巧妙地使用了 mod-rewrite!对问题和答案+1。 :)
    猜你喜欢
    • 2020-01-28
    • 2013-07-06
    • 2016-10-29
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多