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


mod_rewrite - RewriteRule - redirecting to index not showing css,images,etc

我的.htaccess文件中有以下重写规则:

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" />

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

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

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]