mod_rewrite - RewriteRule - 重定向到不显示css,图像等的索引

时间:2015-03-26 14:59:17

标签: php css .htaccess mod-rewrite

我的.htaccess文件中有以下RewriteRules:

RewriteEngine on
RewriteRule ([A-Za-z0-9]+)/ index.php
RewriteRule ^([A-Za-z0-9]+)$ /$1/

我打算将任何目录请求重定向回index.php,保留URI信息进行处理。这些规则允许我这样做,但是一旦索引加载,我的样式表和图像就不会显示出来。我的样式表包括在内:

<link rel="stylesheet" type="text/css" href="/css/chat.css" />

图像以类似的方式包含在内。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您的规则应使用条件来排除实际文件或目录。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([A-Za-z0-9]+)/ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)$ /$1/ [L]