HTACCESS subdirectory redirect

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

mignolo

Established Member
Impact
10
Hi, I have this file:

www.mysite.com/images/example.jpg

if the filename contains "_800" (i.e.: www.mysite.com/images/example_800.jpg)

I rewrite to "img.php"

RewriteRule ^images/([^/]+)(_[0-9]+)(\.(gif|jpg|jpeg|png))$ img.php?img=$1&ext=$4&size=$3&type=$2&height=0&con=i [L]

a script that resizes the image "example.jpg" width to 800px and saves the new image under "images/resized/":

www.mysite.com/images/resized/example_800.jpg

The question is:
How to rewrite

www.mysite.com/images/example_800.jpg
to
www.mysite.com/images/resized/example_800.jpg

when "resized/example_800.jpg" exists, and redirect to

img.php

when "resized/example_800.jpg" doesn't exist?

Andrea
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Hi,

The following should work. It first rewrites to the resized image, then if that does not exist, rewrites to the PHP script.

Code:
RewriteRule ^images/([^/]+_[0-9]+\.(gif|jpg|jpeg|png)$ images/resized/$1

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^images/resized/([^/]+)(_[0-9]+)(\.(gif|jpg|jpeg|png))$ img.php?img=$1&ext=$4&size=$3&type=$2&height=0&con=i [L]
 
0
Close
GREAT! Thank you very much!

Hi,

The following should work. It first rewrites to the resized image, then if that does not exist, rewrites to the PHP script.

Code:
RewriteRule ^images/([^/]+_[0-9]+\.(gif|jpg|jpeg|png)$ images/resized/$1

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^images/resized/([^/]+)(_[0-9]+)(\.(gif|jpg|jpeg|png))$ img.php?img=$1&ext=$4&size=$3&type=$2&height=0&con=i [L]
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back