Solved

Need help modifying modrewrite rule for image to html page redirection

Posted on 2003-10-29
9
219 Views
Last Modified: 2010-03-04
I have this bit of code that needs to be modified. The idea is as follows:

someone links directly to one of 5,300 images on a site (all jpg files). The site returns just the image. I'd like the site to redirect that request to a shtml  file with the same name as the jpg file. So if the file images123.jpg is requested it will give them images123.shtml.

The catch is that the files are all over the place with regards to folders/directories. There are some 400 different directories. The code I have here is hard coded to one directory.  So I need it modified to use the requested directory. The shtml and jpgs are all in the same folders.

Here's the code:


###Display html page for image if only image is requested
RewriteCond      %{HTTP_REFERER} !^$                              
RewriteCond      %{HTTP_REFERER}  !^*\.www.jeffsheliphiles\.com$
RewriteCond      %{REQUEST_URI}  ^*\.www.jeffsheliphiles\.com/images/$
RewriteRule      ^/images(.*).jpg     /html/$1.shtml


Thanks!!!  I put the points at 500 not because it's necessarily hard, but I need an answer quick!!  Also- I am not going to award points until I've tested this live!! So please be patient while I test your answer(s)!!!
0
Comment
Question by:digitalwav
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

Expert Comment

by:kalosi
ID: 9643414
How does the directory structure look like ?? I want to know weather the depth is constant or not.

But this should work file

RewriteRule ^/images/(.*)\.jpg$ /html/$1.shtml

david
0
 
LVL 1

Author Comment

by:digitalwav
ID: 9643527
all the files are /helimg/model or /helimg/model/thumb
0
 
LVL 4

Expert Comment

by:kalosi
ID: 9643566
Ok,

the posted rule should be OK.

david
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 1

Author Comment

by:digitalwav
ID: 9643664
do I need to change anything in the line you've provided?
0
 
LVL 4

Expert Comment

by:kalosi
ID: 9648091
I don't know your real paths or path prefixes. so maybe that
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9648707
You mentioned that « the shtml and jpgs are all in the same folders », so I assume that you actually want

/helimg/model/blah.jpg -> /helimg/model/blah.shtml
/helimg/model/thumb/blah_again.jpg -> /helimg/model/thumb/blah_again.shtml

Correct ? In which case, I would try something like this :

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.jeffsheliphiles.com/.*$ [NC]
RewriteRule ^/helimg/model/(.*)\.jpg$ /helimg/model/$1.shtml

0
 
LVL 1

Author Comment

by:digitalwav
ID: 9649287
_nn_ --The "model" folder/directory is a variable, there are 200+ variations of it.  Can that be passed to the rule? Otherwise I think you have what I'm after.
0
 
LVL 16

Accepted Solution

by:
_nn_ earned 500 total points
ID: 9649386
Well then, let's just remove the model part :

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.jeffsheliphiles.com/.*$ [NC]
RewriteRule ^/helimg/(.*)\.jpg$ /helimg/$1.shtml

An if it's all over the site, then :

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.jeffsheliphiles.com/.*$ [NC]
RewriteRule ^/(.*)\.jpg$ /$1.shtml
0
 
LVL 1

Author Comment

by:digitalwav
ID: 9649555
Perfect right off the bat. And the great thing is that it works for any image or only the ones in the defined directory!

Thanks!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question