Php 允许访问.htaccess中的某些目录和文件
我有一个带有MVC和.htaccess文件的php应用程序,它可以重新定义指向index.php文件的所有链接Php 允许访问.htaccess中的某些目录和文件,php,apache,.htaccess,http,Php,Apache,.htaccess,Http,我有一个带有MVC和.htaccess文件的php应用程序,它可以重新定义指向index.php文件的所有链接 但是我需要访问其他文件夹和文件,如public/css、public/js、public/images和auther…大多数MVC规则包含以下内容: RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f 这是为了防止指向实际文件的URL被重写到mvc。例如,如果您想直接链接到public/css
但是我需要访问其他文件夹和文件,如public/css、public/js、public/images和auther…大多数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
您应该添加一个允许访问这些目录的条件
# 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]
请访问