apache htaccess mod rewrite images + stylesheets fix

Hi

I have been working with httacess mod rewrite for a while now and know the basics (although my reg ex is still very very limited)

I have always come across the same issue with images and style sheets where by i have to use root relative paths to images + stylesheets etc.

1.
Are there any techniques out there to rewite stylesheets and images aswell or do i have to keep using root relative paths?

2.
Be great to hear people opinions on using root relative paths vs document relative paths and their use where site uses mod rewrite.

Looking forward to hearing your thoughts.

Many thanks

--s--
LVL 1
socrossAsked:
Who is Participating?
 
caterham_wwwConnect With a Mentor Commented:
> Are there any techniques out there to rewite stylesheets and images aswell

You can rewrite wrong paths, yes, the easiest way would be if images/stylesheets are in a separate folder

         RewriteRule /(images/.*) /$1 [R=301,L]
will redirect /foo/images/abc... or /foo/bar/images/abc... to /images/abc... (if the requst was /images/... the rule will match in .htaccess files against images/.. only, w/o the leading slash)

> Be great to hear people opinions on using root relative paths vs document relative paths

If you're using a virtual folder structure,  I think you're using absolute links to your html site files - otherwise links may point to wrong locations, too, which is not a good idea (search engines). Another approach instead of an absolute path like /images/foo.jpg (leading slash) is <base href="http://example.com/"> in your <head> section, which should solve the problem, too.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.