Dynadot โ€” .com Transfer

HTACCESS subdirectory redirect

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
•••
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
•••
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
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
NameMaxi - Your Domain Has Buyers
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back