Php .htaccess的公共目录

Php .htaccess的公共目录,php,regex,.htaccess,mod-rewrite,url-rewriting,Php,Regex,.htaccess,Mod Rewrite,Url Rewriting,我在index.php中有一个dispatcher函数,因此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] <

我在index.php中有一个dispatcher函数,因此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> 重新启动发动机 重写cond%{REQUEST_FILENAME}-D 重写cond%{REQUEST_FILENAME}-F 重写规则^(.*)$index.php?url=$1[QSA,L] 如何修改它,使我可以将所有静态文件转储到公共目录中,但在URL中没有公共文件的情况下访问它们

例如/docs/lolcats.pdf访问

/驱动器上的public/docs/lolcats.pdf

我试过这个

RewriteCond %{REQUEST_FILENAME} !f RewriteRule ^(.*)$ public/$1 [QSA,L] 重写cond%{REQUEST_FILENAME}!F 重写规则^(.*)$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
,因为前者会触发子请求。

谢谢,这非常有效!我试图修改它,使其嵌套在另一个目录中工作,但没有成功。例如,如果文件foo.txt位于DOCROOT/mysubdir/public/foo.txt中,什么规则允许我通过www.example.com/mysubdir/foo.txt访问它?我认为这只有在你明确命名子目录的情况下才可能。这个答案的第二部分完全符合我的需要-在“public”目录中显示文件,而不需要在url中指定“public”。@Gumbo我需要类似的答案。请阅读我的,给我任何解决方案-