homepage Welcome to WebmasterWorld Guest from 54.227.5.234
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewrite URL
berm




msg:4542333
 7:53 pm on Feb 4, 2013 (gmt 0)

I am trying to redirect hotlinked images to the image page with .htaccess. The format of the image is:
http://www.mysite.com/images/photos/dog-IMG1234_file4.JPG

I want to capture this and rewrite it to be this:
http://www.mysite.com/cgi-bin/photo.cgi?dog-IMG1234

I know how to redirect to my main page but I dont know how to split the image url up to get out the dog-IMG1234 part. Can someone help me please?

 

g1smd




msg:4542343
 8:34 pm on Feb 4, 2013 (gmt 0)

What code have you tried so far?

A rewrite involves an external URL (with hostname) and an internal filepath (without hostname). Which one is which here?

You have quoted two URLs.

berm




msg:4542348
 9:07 pm on Feb 4, 2013 (gmt 0)

The 1st URL is an image file. The 2nd is a webpage with the photo on it.

berm




msg:4542352
 9:19 pm on Feb 4, 2013 (gmt 0)

This is basically what I have so far, I want to redirect not to my home page but to the photo page, as seen above. It is a dynamic URL, so I need to extract the dog-IMG1234 part out of the original file request and put on the end of my photo.cgi script.


RewriteEngine on

RewriteCond %{HTTP_REFERER} !^http://www.mysite.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|JPG)$ http://www.mysite.com [L]

berm




msg:4542353
 9:22 pm on Feb 4, 2013 (gmt 0)

So I need to remove the URL up until dog-IMG1234, then remove the _file4.JPG part too so I am left with just the dog-IMG1234 part. Thanks!

lucy24




msg:4542387
 11:43 pm on Feb 4, 2013 (gmt 0)

[httpd.apache.org...]

The part you want is
>> RewriteCond >> QueryString

While you are there, refresh your memory on the difference between a rewrite and a redirect. (The functions, not the commands.) Or just read any half-dozen threads in this forum; it's probably more intelligible :)

http://www.mysite.com [L]


The flag says rewrite (there's no R=301) but the form of the target says redirect (full protocol and hostname). The result will be a 302 redirect, which is probably the last thing you want.

g1smd




msg:4542400
 12:41 am on Feb 5, 2013 (gmt 0)

Which one is which here?

The 1st URL is an image file. The 2nd is a webpage with the photo on it.

I understand the question even less than I did before.

berm




msg:4542403
 12:52 am on Feb 5, 2013 (gmt 0)

Image File: (ends with JPG)
http://www.mysite.com/images/photos/dog-IMG1234_file4.JPG

Webpage URL
http://www.mysite.com/cgi-bin/photo.cgi?dog-IMG1234

lucy24




msg:4542410
 2:02 am on Feb 5, 2013 (gmt 0)

Er, yes, we understand that. We understood it the first time and the second time too. We're past that.

g1, I think berm wants something involving

/cgi-bin/photo.cgi?$1

--assuming you can do this with image files-- but I'm waiting for some elucidation about where the hotlinking comes in. So far the proposed RewriteRule is silent about both refers and query strings.

Then again, I've yet to work out how to serve up something with a non-image extension when an image is requested in <img src> form. Possibly it can't be done on my hosting setup, so I should stop beating my brains out over it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved