Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite changed ./ path

when trying to include something else

         

adioe3

2:12 pm on Aug 24, 2007 (gmt 0)

10+ Year Member



Hello all.

I'm using mod_rewrite to substitute
localhost/index.php?m=static&a=someaction
to
localhost/static/someaction

Whilst my RewriteRules do ok for redirection, they change the ./ path for php, so an image in /sitefolder/images/ gets included as /sitefolder/static/images!

Or, more clearly, when opening
localhost/static/somepage
if the page has a <img src="images/image.jpg" /> it gets replaced as <img src="static/images/image.jpg />.

One workaround was to specify the full file location in a variable and paste it all over the place, but is there a simpler way?

jdMorgan

2:50 pm on Aug 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remember that it is the client (e.g. the browser) that resolves relative links. So, by making it appear that the current page is in /static/someaction, you have told the browser to resolve all page-relative links based on that page address; The browser will resolve relative links based on the /static/ directory level.

Four solutions (in no particular order) are:
1) Use server-relative links on the pages, e.g. "/images/logo.gif" instead of "../images/logo.gif"
2) Use fully-qualified links on the pages, e.g. "http://example.com/images/logo.gif"
3) Add an exception to the current rule for all relatively-linked 'included' page objects based on URL-path or filetype.
4) Add another rule to 'correct' the incorrectly-rewritten links.

Jim