Forum Moderators: phranque
I've read that, "You cannot use a RewriteRule to match a query string from a dynamic url" and therefore must use RewriteCond. I've never used RewriteCond and I can't seem to get it.
Here is my particular problem:
OLD (REQUESTED) URL:
http://example.com/photos/watermark.php?file=500/431-file-6-11_01.jpg
NEED TO REWRITE TO (WORKING URL):
http://example.com/photos/dir/500/431-file-6-11_01.jpg
Here is what I've muddled so far:
RewriteCond %{QUERY_STRING} ^file\=([\d]+)/(.+)$
RewriteRule ^$ /photos/dir/%1/%2 [L]
Need I say it's not working? Any ideas? Where do I go from here?
Thanks in advance for your help!
[edited by: encyclo at 5:47 pm (utc) on Nov. 6, 2007]
[edit reason] switched to example.com [/edit]
RewriteCond %{QUERY_STRING} ^file=([0-9]+)/([^\.]+\.jpg)$
RewriteRule ^photos/watermark\.php$ /photos/dir/%1/%2 [L]
Jim
The code you submitted did not work. After a couple more hours and help from another forum, I finally got it to work using the following:
RewriteCond %{QUERY_STRING} ^(.*&)?file=([^&]+)(&.*)?$ [NC]
RewriteRule ^photos/watermark\.php$ /photos/data/%2? [NC,L]
And no, the resulting static URL now points to actual existing directory/file structure. The "watermark" script was changed and caused thousands of legacy image links to stop working. Fortunately, the legacy links contained all the dir and file info needed to redirect to actual image locations... Except without a "Watermark"...
[edited by: jdMorgan at 2:13 pm (utc) on Nov. 5, 2007]
[edit reason] Disabled smilies in code [/edit]
You can shorten that code and make if more efficient:
RewriteCond %{QUERY_STRING} &?file=([^&]+) [NC]
RewriteRule ^photos/watermark\.php$ /photos/data/%1? [NC,L]
Jim