Msg#: 4424548 posted 4:47 pm on Mar 3, 2012 (gmt 0)
Ive just finalized my htaccess to force the trailing slash on my urls. However now I have another problem. The images are not showing up unless I add the absolute path to the image. Here's how it looks
/products /products - index.html (images showing on this page without absolute url) /products - example.html (images not showing unless I write the absolute url)
Msg#: 4424548 posted 4:53 pm on Mar 3, 2012 (gmt 0)
If the link to your image is href="images/image.png" this is what happens:
From page at: example.com/thispage the browser will evaluate the image link as pointing to: example.com/images/image.png
From page at: example.com/thispage/ the browser will evaluate the image link as pointing to: example.com/thispage/images/image.png
You should change your image link from href="images/image.png" to href="/images/image.png" beginning with a leading slash so that it counts from the root.
There are a large number of errors in your example htaccess code.
RewriteEngine on should appear only once.
Add a blank line after every RewriteRule so you can clearly see which bits of code belong together.
The index redirect must be listed before the domain redirect otherwise some requests will create an unwanted multiple step redirection chain.
Literal periods must be escaped.
The domain redirect doesn't cater for all requests: !^www.mysite.com$ should be !^(www\.mysite\.com)?$ so that pure HTTP/1.0 requests do not create a loop.
Your index redirect works only in the root, not in folders. Do not use (.*) as a pattern to fix that.
Your "add a slash" redirect should be before the domain redirect otherwise it will invoke an unwanted multiple step redirection chain for some requests. However, why are you adding a slash? URL ending in slash is for a folder. URLs for pages do not end with a slash but may have an optional extension (I prefer extensioness URLs for pages). Files, such as images and stylesheets, always have an extension.
The "-f" test is very slow and inefficient. There are much better ways to invoke a rewrite, especially where URLs for pages are extensionless. If you really do have to use the "-f" test, make sure the Rule pattern or the pattern in a preceding RewriteCond tests the extension and only allows the "-f" test to proceeed if there is actually a chance that this request will be rewritten, i.e. exclude image and stylesheet extensions.