如何调整多部分URL的.htaccess

时间:2015-06-26 19:11:47

标签: php apache .htaccess

我正在尝试让我的代码接受以下网址:

www.mysite.com/something/something2/something3/something4

我在.htaccess中使用了以下代码,因此请求通过index.php文件运行:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

如果网址为www.mysite.com/something,则可以正常使用。

但是,如果我将其更改为www.mysite.com/something/something2,则在加载CSS等外部文件时出现问题。

不是加载请求的CSS文件,而是加载index.php。

仅当域之后有超过1个段时才会这样。否则,它加载CSS就好了。

以下是我加载CSS的方法:

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

1 个答案:

答案 0 :(得分:1)

由于您告诉Apache将所有URI视为index.php,因此您的所有路径都必须是绝对路径,或者相对于index.php。例如:

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

(最初评论)