你好,我有以下文件结构:
/public_html(docroot)
- /public
/css
/js
index.php
- /application
- /library
注意:我无法更改此结构。我想要的是:所有对文件的请求都应该从公共文件夹打开文件,所有其他请求都应该转到index.php。目前我在public_html:中有下一个.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
但它只适用于http://hostname/public
。没有public
怎么能工作?谢谢
我找到了答案:
RewriteEngine On
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]