homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Rewrite URL

 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:

I want to capture this and rewrite it to be this:

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?



 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.


 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.


 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]


 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!


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


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.


 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.


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

Image File: (ends with JPG)

Webpage URL


 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


--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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved