我正在应用这个modrewrite规则的问题。
它按预期工作,但在查看页面时,它期望所有脚本/ css /图像的绝对路径。所以除非我单独检查每一个并在其前面添加“../”(即'icons / book.gif'=>'../ icons / book.gif'),否则不会显示这些内容。
有没有办法用modrewrite本身解决这个问题?这是我正在申请的规则:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^category/([A-Za-z\+]+)/?$ fact.php?category=$1
</IfModule>
编辑:此功能将确定绝对路径,建议用于站点上的所有链接。
// determines and returns the absolute url path
function absolute_url ($page = "index.php") {
$url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// remove trailing slashes
$url = rtrim($url, '/\\');
// add the page
$url .= "/" . $page;
return $url;
}
答案 0 :(得分:1)
你的规则如下:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^category/([A-Za-z\+]+)/?$ fact.php?category=$1 [L,NC]
这将避免重写现有文件(静态文件,如css,js,images)。
或者,您可以将HTML base tag这样用于静态文件:
<base href="http://www.example.com/static/" />
但是,建议始终对静态文件使用绝对路径。