Solved

Need help modifying modrewrite rule for image to html page redirection

Posted on 2003-10-29
9
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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