我想使用 .htaccess
file 检查请求的路径是否是 public/
中的文件目录。如果是,提供它,否则将请求转发到 /index.php
.我似乎无法让它发挥作用。
这是我所拥有的:
Options +FollowSymLinks
RewriteEngine on
Options -Indexes
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
RewriteRule ^ %{DOCUMENT_ROOT}/public%{REQUEST_URI} [L]
RewriteRule ^ index.php [QSA,L]
例如
http://example.com/css/style.css
应该有 apache 服务 /public/css/style.css
因为它是一个存在的文件,但是 http://example.com/css/style.bad
应发送至 /index.php
.
最佳答案
此代码应该在您这边按预期工作
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{THE_REQUEST} \s/public/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L,QSA]
关于apache - .htaccess:提供静态文件,将其他所有内容路由到 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25956054/