Forum Moderators: phranque
I'm just in the process of moving my images from names like 040512.1.jpg to some_really_good_name.jpg and have set up a DB table and php script to handle the redirection. That bit's working fine, however, I have also been using a little .htaccess and php script that checks for the referrer and if it isn't my site writes http://mydomainname onto the bottom of the image.
With the second script in place I get a 500 error, without it all is well, but there's no attribution on the images. I'd really like it to work how it used to :-)
many thanks for your help,
Andy
here's the .htaccess of the second script:
RewriteBase /visible_code/
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^mysite
RewriteRule ^(.*)\.jpg$ att_file.php?file=$1.jpg [L]
[edited by: jdMorgan at 2:41 am (utc) on June 16, 2005]
[edit reason] De-linked. [/edit]
RewriteCond %{REQUEST_FILENAME}!-s
RewriteRule ^([a-z0-9_/\.]{3,255}[jpg¦php])$ old_to_new.php?url=$1 [L]
thanks for your help,
Andy
Here, this code is bad, and might be the cause. I can't be sure:
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([a-z0-9_/\.]{3,255}[jpg¦php])$ old_to_new.php?url=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([a-z0-9_/\.]{3,255}(jpg¦php))$ old_to_new.php?url=$1 [L]
Then, in order to prevent the looping, exclude the substitution URL from being rewritten:
[b]RewriteCond %{REQUEST_URI} [i][/i]!^old_to_new\.php$[/b]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([a-z0-9_/\.]{3,255}(jpg¦php))$ old_to_new.php?url=$1 [L]
Replace the broken pipe "¦" characters above with solid pipe characters before use. Posting on this board modifies them.
Jim
sorry for the lack of information - I was trying to be concise and got the balance wrong, I'd only read the error message, log and turned on LogLeve debug after reading your post.
With your help I think the problem is now solved and the pattern is more accurate and a little more efficient. It now reads:
RewriteCond %{REQUEST_URI} ^/[a-z0-9_/-]{3,255}$
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ([a-z0-9_/-]{3,255}) page_handler.php?url=$1
#Redirect old pages into the new format
RewriteCond %{REQUEST_FILENAME}!-s
RewriteRule ^([a-z0-9_/\.]{3,255}(jpg¦php))$ old_to_new.php?url=$1 [L]
#-------------------------------------------------------------------#
# IMAGE ATTRIBUTION#
#-------------------------------------------------------------------#
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?(a)?b(c)?d
RewriteRule ^(.*)\.jpg$ /common_files/functions/attribution.php?file=$1.jpg [L]
-> (www/.)?(a?)b(c?)d
I own www.abcd.com www.bcd.com and www.abd.com but not other variations. I left off the .com because my test server is called abcd and I'm assuming that www.abcd.net etc won't cause me problems. This pattern seems to work, but if it can be improved... :-)
The!-s and!-d inefficiency. The!-s has to go I guess, as the site gets pushed more into the db and is less in the 'real' directory structure the pattern becomes more and more of a waste. I was thinking I should use a php script by default to check the DB and then use that to check the file structure if it's not found. Does that sound like a better way to go? the!-d should cease to exist once the data has been fully moved.
many thanks,
Andy
RewriteCond %{HTTP_REFERER} !^http://(www\.)?a?bc?d
RewriteCond %{HTTP_REFERER}!^http://(www\.)?(abcd¦bcd¦abd)
I wouldn't worry *too* much about the mod_rewrite file-checking, just avoid it if possible. Comparing that to doing a database lookup on each request, the mod_rewrite check will probably be much faster, unless the database is kept in memory. You might want to work toward a known list of static files or filetypes that *do* exist, rather than using any kind of dynamic checking. This may or may not be a viable solution for your specific site, just an idea... Processing a list in code or memory will always be much faster than going to the filesystem.
Jim
I'll take the risk on bcd-displays.com :-)
(edit: actualy, I might go to go with (a¦bcd\.com¦abd\.com) which looks like the most specific. Thinking: if I permanent redirect the other domains into the main one and non-www into www then I don't need this at all, right? )
I'll see how many static pages are left in couple of weeks and see about a static list,
many thanks
Andy