1

我有效地使用重写规则将我的网址从 /teams.php?team=New York Yankees&year=2012 更改为 teams/New York Yankees/2012。

我的 .htaccess 文件包含以下内容

RewriteEngine On
RewriteRule ^teams/([^/]*)/(^/]*)$ /teams.php?team=$1&year=$2 [L]

但是,由于此重写规则当前生效,将不会加载任何外部 CSS 和 JS 文件。我尝试将以下重写条件放在重写规则之前,但没有成功

RewriteCond %{REQUEST_URI} !^/(css/js)/

几乎我所有的文件都有以下指向外部样式表的链接。

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

有什么想法我在这里做错了吗?

谢谢

4

1 回答 1

1

链接到样式表时必须使用完整路径,而不是像现在这样的相对路径。随着重写规则的到位,它们变得相对于预先重写的 URL。

例如,更改:

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

到:

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

他们没有加载的原因是浏览器试图访问:

http://yoursite.com/teams/New York Yankees/2012/css/stylesheet.css

当你链接到css/stylesheet哪个当然不存在。

于 2012-07-24T00:41:39.433 回答