.htaccess RewriteCond使用缓存的页面如果存在不起作用

问题描述

我在共享主机软件包上安装了laravel应用程序,并且正在使用https://github.com/JosephSilber/page-cache来缓存页面

缓存的页面存储在以下服务器文件/home/username/public_html/app_name/public/page-cache/article

以下代码位于公共文件夹的.htaccess中

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On


    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Serve Cached Page If Available...
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/public/page-cache/pc__index__pc.html -f
    RewriteRule .? public/page-cache/pc__index__pc.html [L]
    RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.html -f
    RewriteRule . public/page-cache%{REQUEST_URI}.html [L]
    RewriteCond %{DOCUMENT_ROOT}/public/page-cache%{REQUEST_URI}.json -f
    RewriteRule . public/page-cache%{REQUEST_URI}.json [L]
    
    

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.PHP [L]
    
    
    
</IfModule>

我尝试调试DOCUMENT_ROOT和REQUEST_URI的值,并且得到以下信息: %{DOCUMENT_ROOT} = /home/username/public_html/app_name and %{REQUEST_URI} = /article/race-policing-and-the-universal-yearning-for-safety

使用.htaccess中的上述代码,即使文件存在,我也无法将其定向到缓存页面,但是可以直接将其定向到应用程序。

例如/home/username/public_html/app_name/public/page-cache/article/race-policing-and-the-universal-yearning-for-safety.html

app_name文件夹中还有以下.htaccess文件

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


   RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1

#disable directory browsing
Options -Indexes

#PROTECT ENV FILE
<Files .env>
order allow,deny
Deny from all
</Files>

#PROTECT ENV FILE
<Files .htaccess>
order allow,deny
Deny from all
</Files>

如果有人可以帮助我确定.htaccess在存在缓存页面时未加载的原因,我将不胜感激。保持安全:)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)