开发者

Modrewrite Makes Scripts/CSS not appear due to their path location

I'm having issues with this modrewrite rule I'm applying.

It works as intended, but when view开发者_运维知识库ing the page, it's expecting an absolute path for all my scripts/css/images. So those won't display unless I go through each one individually and prepend "../" to them (i.e. 'icons/book.gif' => '../icons/book.gif')

Is there a way to fix this with modrewrite itself? Here is the rule I'm applying:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule  ^category/([A-Za-z\+]+)/?$ fact.php?category=$1
</IfModule>

EDIT: This function will determine the absolute path, which is recommended to use for all links on the site.

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

}


Have your rules like this:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule  ^category/([A-Za-z\+]+)/?$ fact.php?category=$1 [L,NC]

This will avoid rewriting for files present (static files like css, js, images).

Alternatively you can use HTML base tag like this for static files:

<base href="http://www.example.com/static/" />

However it is recommended to always use absolute path for static files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜