Forum Moderators: phranque
So it *should* do the following, right?
User Enters:
example.com/t1/t2/
Apache Redirects to:
example.com/showpicture.php?image=gallery/apic100.jpg
The page itself loads. But all the content on the page is broken. It acts like Apache is failing to set the RewriteBase to the root folder.
I'm lead to wonder because this alternative rule works fine:
RewriteBase /
RewriteRule ^t1_t2$ showpicture.php?image=gallery/apic100.jpg [NC]
where User Enters:
example.com/t1_t2
Apache Redirects to:
example.com/showpicture.php?image=gallery/apic100.jpg
But I don't want underscores in my URL! I want slashes for pseudo directories!
Can anyone tell me what's wrong?
[edited by: jdMorgan at 8:39 pm (utc) on Jan. 27, 2006]
[edit reason] Example.com [/edit]
The browser believes that the resource's URL is example.com/t1/t2/
It will therefore resolve any relative link it finds on pages for images and/or included scripts or stylesheets by using /t1/t2/ as it's 'current' directory loation, and resolving relative links based upon that URL-path.
There are two easy solutions. First, you can use canonical or server-relative links on your pages to locate images and scripts, e.g. <img src="http://www.example.com/images/widget.gif"> or <img src="/images/widget.gif">
Alternatively, you can implement rewriterules that also rewrite the resource requests from the relocated pages, e.g.
# rewrite pic requests to script
RewriteRule ^t1/t2/$ showpicture.php?image=gallery/apic100.jpg [NC]
# rewrite css requests to styles directory
RewriteRule ^t1/t2/(.+)\.css$ /styles/$1.css [NC]
Also, while testing, I'd suggest you server-anchor the substitution URL as appropriate. For example:
RewriteRule ^t1/t2/$ [b]/sh[/b]owpicture.php?image=gallery/apic100.jpg [NC]
You can find out what URL-path is failing by looking at your raw server error logs after loading a page with broken images, etc. on it. It will show the failed request and the filepath resolved from the URL. That's often a good clue on how to fix the problem.
Jim