gpt4 book ai didi

.htaccess - mod_rewrite : If the file exists in another directory, 改为服务那个

转载 作者:行者123 更新时间:2023-12-04 07:25:45 24 4
gpt4 key购买 nike

我有一个网站 example.com/test/ .假设网站的布局如下:

example.com
└── test/
   ├── assets/
│ └─ stylesheet.css

├── .htaccess
└── index.php
index.php这是路由器,现在显然很酷。

每当用户请求像 example.com/test/stylesheet.css 这样的页面时,我想看看 assets/有该文件,如果有,提供该文件而不是将 URL 提供给 index.php .理想情况下,以下内容将起作用:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond assets/%{REQUEST_FILENAME} -f
RewriteRule ^(.+)$ assets/$1

但由于 %{REQUEST_FILENAME}是绝对路径, assets/%{REQUEST_FILENAME}原来是这样的 assets/home/public/test/stylesheet.css . %{REQUEST_URI}没有更好:它变成 assets/test/stylesheet.css .我也看了 this question ,但答案也不起作用。

有没有办法在不求助于 PHP 的情况下做到这一点? (如果没有,我将只使用 PHP 的 readfile ,但我不想担心 LFI 或任何东西。)

最佳答案

尝试使用 the %{DOCUMENT_ROOT}%{REQUEST_URI}变量

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/assets/%{REQUEST_URI} -f
RewriteRule ^(.+)$ assets/$1

编辑:我明白了,试试这个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.+)$
RewriteCond %{DOCUMENT_ROOT}/%1/assets/%2 -f
RewriteRule ^(.*)$ /%1/assets/%2 [L,R]

关于.htaccess - mod_rewrite : If the file exists in another directory, 改为服务那个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12031374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com