我有一个带有MVC和 .htaccess 文件的php应用程序,该文件重新指向文件index.php的所有链接 但是我需要访问其他文件夹和文件,如public / css,public / js,public / images和auther ....
答案 0 :(得分:0)
大多数MVC规则包含以下内容:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
这是为了防止将指向实际文件的URL重写到您的mvc。如果您想直接链接到public/css
,而是转到/css
,例如,您需要在MVC规则之前添加规则,如下所示:
RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(css|js|images)/(.*)$ /public/$1/$2 [L]
这会在内部将/css/some/stylesheet.css
重写为/public/css/some/stylesheet.css
。
答案 1 :(得分:0)
您应该添加允许访问这些目录的条件。
# Requested filename does NOT contain index.php, resources, or robots.txt
RewriteCond $1 !^(index\.php|resources|robots\.txt)
# Requested file does NOT exist
RewriteCond %{REQUEST_FILENAME} !-f
# Requested directory does NOT exist
RewriteCond %{REQUEST_FILENAME} !-d
# If all the above rules are true, redirect to index.php/$1
RewriteRule ^(.*)$ index.php/$1 [L,QSA]