我在index.php中有一个调度程序函数,因此URL如下:
/博客/显示转到
/index.php/blog/show
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
我如何修改它,以便我可以将所有静态文件转储到公共目录中,但在 URL 中不使用 public 的情况下访问它们。
例如 /docs/lolcats.pdf 访问
驱动器上的 /public/docs/lolcats.pdf
我试过这个
RewriteCond %{REQUEST_FILENAME} !f
RewriteRule ^(.*)$ public/$1 [QSA,L]
尝试这个:
RewriteCond %{DOCUMENT_ROOT}public%{REQUEST_URI} -f
RewriteRule !^public/ public%{REQUEST_URI} [L]
如果你想在根目录下的子目录中使用它:
RewriteCond %{REQUEST_URI} ^/subdir(/.*)
RewriteCond %{DOCUMENT_ROOT}subdir/public%1 -f
RewriteRule !^public/ public%1 [L]
我找到了另一个没有明确命名子目录的解决方案:
RewriteRule ^public/ - [L]
RewriteCond public/$0 -F
RewriteRule .* public/$0 [L]
重要的改变是使用-F
代替-f
因为前者触发了子请求。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)