Forum Moderators: phranque

Message Too Old, No Replies

Question on mod_rewrite

Links of the rewritten page point to the wrong place

         

morchimorchi

1:53 am on Sep 17, 2005 (gmt 0)

10+ Year Member



Greetings everyone,

The situation is like this, I used mod_rewrite to redirect my ugly page like test.php?value=abc
The rewrite rule is:
RewriteRule ^/test/(.*)$ /test.php?value=$1 [L]

When I enter www.mydomain.com/test/123, the page indeed redirect to my test.php?value=123, which is all correct, but my test.php contains images links like src='images/123.gif' I noticed that after I used the above rewrite my images is loading a link from www.mydomain.com/test/images/123.gif which obviously cannot be found.

When I use [R,L] in the rewrite rule everything works fine though....

Anyone have any idea how to solve this?

Morchi

jdMorgan

2:31 am on Sep 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The key to figuring this out is that it is the browser that resolves relative links. So, as far as the browser is concerned, it is rendering content from a page at example.com/test/123 -- it does not know the URL-path has been rewritten inside the server.

Therefore, a relative link like "images/123/" is resolved to the same directory as the page "123", plus "images/123.gif", yielding an image URL of example.com/test/images/123.

The simplest way to fix/avoid this problem is to always use server-relative or canonical URLs on your pages, such as


<img src=[b]"/i[/b]mages/123.gif">

-or-

<img src="http://www.example/com/images/123.gif">

Jim

morchimorchi

4:27 am on Sep 17, 2005 (gmt 0)

10+ Year Member



oops~ I got everything working fine now~
Thanks a lot~~
^O^