Welcome to WebmasterWorld Guest from 54.221.49.52

Forum Moderators: incrediBILL

Message Too Old, No Replies

images not showing up after I updated my htaccess

     

Mister206

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)

Any ideas?

ErrorDocument 404 /404page.html
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mysite.com$
RewriteRule ^(.*)$ [mysite.com...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ [mysite.com...] [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]

Let me know if you need more info.

Mister206

4:52 pm on Mar 3, 2012 (gmt 0)



I just found this thread. Does this shed any light on what Im doing wrong?

[webmasterworld.com...]

g1smd

4:53 pm on Mar 3, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month