Solved

Need help modifying modrewrite rule for image to html page redirection

Posted on 2003-10-29
9
200 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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 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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

23 Experts available now in Live!

Get 1:1 Help Now