Link to home
Start Free TrialLog in
Avatar of digitalwav
digitalwavFlag for United States of America

asked on

Need help modifying modrewrite rule for image to html page redirection

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)!!!
Avatar of kalosi
kalosi

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
Avatar of digitalwav

ASKER

all the files are /helimg/model or /helimg/model/thumb
Ok,

the posted rule should be OK.

david
do I need to change anything in the line you've provided?
I don't know your real paths or path prefixes. so maybe that
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

_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.
ASKER CERTIFIED SOLUTION
Avatar of _nn_
_nn_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!!