Forum Moderators: phranque
[webmasterworld.com...]
I'm brand new to Rewrites. I have a dynamic site I want to run all my newer stuff through the rewrite rule (I'm afraid to mess with the older stuff for fear of ranking issues)
Here's my very simple rule:
RewriteRule ^DVD/.*_(.*)\.htm$ /show.php?i=$1 [L]
The DVD/ folder is 100% made up. There is no DVD folder anywhere. So basically, existing references like:
Blue-Widgets_23441.htm
Green-Widgets_7466.htm
will NOT trigger a rewrite, but newer items being added are being changed like this:
DVD/Yellow-Widgets_124.htm
DVD/Red-Widgets_7655.htm
If I break down the Rule above, wouldn't it be:
RewriteRule ^DVD/Red-Widgets_7655.htm /show.php?i=7655
When I do this, all my relative paths are out of wack. But I don't know why. I thought the rewrite is EXACTLY like entering show.php?i=7655 in your browser. Are the images looking for DVD/image.jpg? If so, that's the part I don't get. My book tells me to perform a RewriteBase only if my files are not in the root. I've also tried "RewriteBase /" with the same results.
Any way around this? I've got includes that call other includes and on and on. It's a lot of path changing to search around and deal with.
In short, the browser 'thinks' that it is viewing a page in the /DVD subdirectory, and will resolve all relative links on the page accordingly. This can be verified with any HTTP headers checker, such as the "Live HTTP Headers" add-on for Firefox and Mozilla-based browsers.
There are two possible solutions: First, instead of using page-relative object links, you can refer to objects (images) using a server-relative URL-path like <img src="/images/disk-7655.jpg"> or a canonical URL such as <img src="http://example.com/images/disk-7655.jpg">. Alternatively, you could internally rewrite all image requests to remove the 'fake' directory paths, such as /DVD.
Jim