Forum Moderators: phranque

Message Too Old, No Replies

Redirecting Images

image reidirection with mod_rewrite and php

         

mhbernheim

5:56 pm on Apr 27, 2008 (gmt 0)

10+ Year Member



Hi fellas, i have a quick question;

I have this folder http://www.example.com/wp-content/gallery

inside gallery i have .htaccess with the following rules


RewriteEngine On
RewriteRule ^(.*\.jpg)$ http://www.example.com/wp-content/gallery/page.php?img=http://www.example.com/wp-content/gallery/$1 [L]

further page.php has


Go back to FrontPage
<img src="<?php echo $_GET['img']; ?>">

however, this doesn't seem to be working; basically what i want is for the images to be shown through page.php so that I may be able to put a menu on the top of the page.php, help is greatly appreciated

thank you!

[edited by: jdMorgan at 9:06 pm (utc) on April 27, 2008]
[edit reason] No URLs, please. See Terms of Service. [/edit]

mhbernheim

9:11 pm on Apr 27, 2008 (gmt 0)

10+ Year Member



sorry about that, thanks for letting me know

jdMorgan

12:38 pm on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd recommend that you use a local filesystem read (a file 'include') in your PHP, rather than invoking a second HTTP request (effectively making the server request the image from itself via HTTP (which is comparatively very slow) instead of simply reading the image file from the disk that's sitting right there.)

If you do not use periods in your directory name, then the pattern "^([^.]+\.jpg)$" would be more efficient than the one you're using.

If you use a local filesystem read in your script, your rule would then become:


RewriteEngine on
RewriteRule ^([^.]+\.jpg)$ /wp-content/gallery/page.php?img=$1 [L]

Jim