0

I have been digging but maybe I missed it.

I want all my images under /images/user-images to redirect to a php file.

Example: http://domain.com/images/user-images/Montreal/private/2012_08_10/YzAbCdE.jpg

to goto http://domain.com/photo

but I want to be able to know which image they still requested. The URL path does not need to change, just that if request that path they get the image on a webpage so I can skin it.

This is my current mod rewrite which I have in use.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^css/.*$ - [PT]
RewriteRule ^js/.*$ - [PT]

Thanks.

Sukh
  • 361
  • 2
  • 5
  • 11

2 Answers2

2
RewriteRule ^images/user-images/(.*)$ /my-php-file.php?image=$1

The image requested will be available in $_GET['image'] in the form of Montreal/private/2012_08_10/YzAbCdE.jpg.

jeroen
  • 91,079
  • 21
  • 114
  • 132
  • The page redirects to the template I need but I can't load the image into image tag. `code` – Sukh Aug 13 '12 at 16:04
  • try var_dump($_GET['image']); to troobleshoot the issue ! – HamZa Aug 13 '12 at 16:12
  • @jeroen /Montreal/public/2012_08_10/7323_jpre5gvhp1_6hz8q6vhu1.jpg – Sukh Aug 13 '12 at 16:12
  • 1
    @Sukh You cannot request the image like that as it will redirect to the php script :-) What you need to do if the image exists there and you want to use this rewrite, is serve the image direcly from php (return an image header and echo its contents). – jeroen Aug 13 '12 at 16:14
  • 1
    @Sukh This is a start: http://stackoverflow.com/questions/1851849/output-an-image-in-php Note that php will be able to access the image file without any problems, it's just that you can't request it through the web-server any more using the rewrite rule above. Also note that your html should look something like: `` – jeroen Aug 13 '12 at 16:21
  • @jeroen what do I do in the case of http://domain.com/images/user-images/Montreal/private/2012_08_10/YzAbCdE.jpg?lang=fr the FR variable does not get pulled in as GET var – Sukh Aug 15 '12 at 14:50
0

Mod_rewrite is an overkill for this. This would do it as well

Alias /images/user-images /photo

Cœur
  • 37,241
  • 25
  • 195
  • 267
salah-1
  • 1,299
  • 11
  • 15