RewriteCond regexp没有拍摄图像

时间:2013-12-26 19:53:19

标签: regex .htaccess mod-rewrite

拥有以下代码我无法配置.htaccess。它需要.js和.css文件,但不需要.png图像

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^(.*)/\.(jpg|css|js|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)$  index.php?$1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4&$5=$6

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

RewriteCond条件会应用于紧随其后的RewriteRule,因此您只能将这些条件应用于第一条规则。如果您希望将它们应用于其他2条规则,则需要复制它们:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^(.*)/\.(jpg|css|js|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)$  index.php?$1=$2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^(.*)/\.(jpg|css|js|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^(.*)/\.(jpg|css|js|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$  index.php?$1=$2&$3=$4&$5=$6