I am using mod_rewrite in my haccess to make clean URLs. The working directory is webroot/subdir and htaccess resides in subdir
What I have works fine for the main folder
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^projects/([0-9]+)$ ?action=projects&id=$1
RewriteRule ^projects ?action=projects
RewriteRule ^clients ?action=clients
RewriteRule ^admins ?action=admins
RewriteRule ^settings ?action=settings
so those links would be like webroot/subdir/projects or webroot/subdir/settings and they work.
My problem occurs on the projects line where I have to add an id. When I click a link that says something like: webroot/subdir/projects/284, all my style sheets and images break. My CSS is setup like so:
<link rel="stylesheet" href="resources/css/reset.css" />
<link rel="stylesheet" href="resources/css/main.css" />
<link rel="stylesheet" href="resources/css/buttonPro.css" />
Is there a way around this? Am I doing my rewrite rules wrong?
Assuming that your
resourcesfolder is also inwebroot/subdir, you need to make your links absolute paths. When the page changes toprojects/([0-9]+), your working directory now becomeswebroot/subdir/projectseven though the path is being rewritten, so it is trying to look up your style sheets atwebroot/subdir/projects/resourceswhich doesn’t exist.Adding a
/to the beginning of your locations should work:If your resources folder is outside the home/root directory, you will need to specify the full path to that directory, like this: