mod_rewrite trouble

 May, 04 - 2009   no comments   Uncategorized

I’m going to keep my eyes open for an actual explanation for this behavior, but I thought I’d share a problem (and solution?) I ran into with mod_rewrite.

I was going about my business, doing the classic mapping of http://mydomain/subdir/var1/var2 to http://mydomain/subdir/index.php?id=var1&id=var2

I had two rules, one to handle a single variable, and another to handle two variables. The idea, of course, being to drill down to a deep link. It was working great for the single variable rule, as long as I didn’t include a trailing slash. Even though my rewrite regular expression clearly stated that the trailing slash was optional. To taunt me even more, if I changed the rewrite to a redirect, it worked fine.

As it turned out, the page in question contains a frameset (I know, I know) and the frame source parameters were relative paths. Even though the page source URL had been re-written, the frame source URLs were attempting to load pages that weren’t there. Changed the paths to absolute and everything works great.

Just something else to look at if you’re having trouble with mod_rewrite, especially if some rules appear to work, and others don’t. The frameset situation is going to be pretty rare, but the same problem might manifest with missing images, style-sheets, etc.

Related articles

Leave a Reply

Your email address will not be published. Fields with * are mandatory.