Andy Holmes
Andy Holmes

Reputation: 8077

css, images and vendor folders do not load when using htaccess rewrite

Below is the htaccess scripti am using:

Options +FollowSymlinks
RewriteEngine On

RewriteRule ^gecko/([^/]*)$ gecko.php?gecko=$1 [L]

Which changes http://localhost/geckology/gecko.php?gecko=Zilly (which loads css etc fine) to http://localhost/geckology/gecko/zilly which doesn't load the css etc fine as it looking in directories like this http://localhost/geckology/gecko/css/theme.css when it should be http://localhost/geckology/css/theme.css

The site is huge, so if possible i would like a htaccess way of fixing this, however i will change everything to absolute urls if it's not possible

Upvotes: 1

Views: 109

Answers (1)

Jon Lin
Jon Lin

Reputation: 143916

You can fix the relative URI base by simply adding this to the header of your pages:

<base href="/" />

or if you have to use htaccess, which is really inefficient and will assume all of your css/scripts/etc are all in one place, while at the same time making the rest of the world think the same thing is actually 2 different URLs:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^gecko/(css|images|other)(/.*)$ /$1/$2 [L]

This blindly rewrites any URL that tries to access "css", "image" or "other" folders within the /gecko/ path.

Upvotes: 1

Related Questions