I’m having issues with this modrewrite rule I’m applying.
It works as intended, but when viewing 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:
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:
However it is recommended to always use absolute path for static files.