Css和javascript没有加载重写条件?

时间:2011-11-14 11:28:32

标签: mod-rewrite

  

可能重复:
  Css and javascript Not Loading in rewrite rule

仅使用重写规则

RewriteEngine On
 RewriteRule ^profile.php$ profile.php

当我加载profile.php时,正在加载css和javascript

但是当改变规则并添加条件时

RewriteEngine On
RewriteCond %{REQUEST_URI} !/profile.php$
 RewriteRule ^profile.php$ profile.php

然后js和css没有加载

profile.php的编码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-…
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 <title>Untitled Document</title>
 <link rel="stylesheet" href="http://localhost/css/profile.css" />
 </head>
 <body>
 <table><tr><td><div class="image"><ul><li>My</li></ul></div>
 </td></tr></table>
 </body></html>

1 个答案:

答案 0 :(得分:1)

这是因为RewriteCond说:apply the following RewriteRule only if the url doesn't only contain /profiles

你应该写它:

RewriteCond %{REQUEST_URI} /profile.php$

(没有感叹号)

补充说: 如果您不希望将mod_rewrite规则应用于脚本和其他特定文件请求,则应为它们编写规则。

E.g。

RewriteRule \.(css|jpe?g|gif|png)$ - [L]