Solved

Need help modifying modrewrite rule for image to html page redirection

Posted on 2003-10-29
9
189 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
 
LVL 1

Author Comment

by:digitalwav
ID: 9643664
do I need to change anything in the line you've provided?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now