[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 671
  • Last Modified:

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--
0
socross
Asked:
socross
1 Solution
 
caterham_wwwCommented:
> 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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now