Forum Moderators: phranque
RewriteCond %{REQUEST_URI} ^/images/([0-9]+)
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com$
RewriteRule (.*) htp://www\.example\.com/view.php?user=%1&showimage=%2
(some of the contents of my .htaccess file. the htp:// is on purpose, to prevent WW making a link)
What I'm trying to do is to capture a variable in the first RewriteCond, another variable in the second RewriteCond and then use both variables in the RewriteRule. Weirdly enough, it's capturing the second variable, but not the first. And it's placing the second variable where the %1 is!
It's almost as if the first variable is being overwritten by the second rewritecond. I've swapped the rewritecond lines around and it still only captures the second variable.
Can any of the eminently bright minds at WW help me out? Thanks!
You're lucky in that a simple re-arrangement of your code will fix it:
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule ^images/([0-9]+)$ http://www.example.com/view.php?user%1&showimage=$1
Another way to address the generic problem of accessing back-references to different server variables, although unnecessary in this case, would be something like:
RewriteCond %{REQUEST_URI}<>%{HTTP_HOST} ^www\.([^.]+)\.example\.com[^<]*<>/images/([0-9]+)
RewriteRule .* http://www.example.com/view.php?user=%2&showimage=%1
Other minor edits on pattern-anchoring and character-escaping were needed; The code shown above is as correct as I can make it, given my understanding of your code.
Jim