首页 > 解决方案 > htaccess - 如何允许访问其他文件

问题描述

目前我有以下 htaccess 文件:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /v2/index.php?pg=$1 [L]
</IfModule>

什么在起作用?

http://site/v2/test -> 转到http://site/v2/index.php?pg=test

什么不工作?

如果我想加载 css 或 zip 文件.. http://site/v2/_downloads/download.zip 它转到: http://site/v2/index.php?pg=_downloads/download.zip

但我想转到实际页面相同的 css 出于某种原因它加载: http://site/v2/index.php?pg=_css/style.css 而不是http://site/v2/_css/style.css

我做错什么了?就是看不出来。。

标签: php.htaccessmod-rewrite

解决方案


这似乎可以解决问题

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|\.bat|\.zip|\.rar|robots\.txt)$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^(.*)$ /v2/index.php?pg=$1 [L]
  #RewriteRule ^(.*)/$ v2/index.php?pg=$1 [L]
</IfModule>

推荐阅读