NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page HTACCESS subdirectory redirect

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 11-08-2009, 07:33 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
mignolo's Avatar
Join Date: Mar 2007
Posts: 460
mignolo is a jewel in the roughmignolo is a jewel in the roughmignolo is a jewel in the rough
 



Help! HTACCESS subdirectory redirect


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/":
????: NamePros.com http://www.namepros.com/programming/621778-htaccess-subdirectory-redirect.html

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
__________________
RodeoArena.com for Sale, PM for Offers
mignolo is offline   Reply With Quote
Old 11-08-2009, 11:25 AM   #2 (permalink)
NamePros Regular
 
qbert220's Avatar
Join Date: Jul 2007
Location: UK
Posts: 394
qbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to behold
 


Protect Our Planet
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]
qbert220 is offline   Reply With Quote
Old 11-08-2009, 03:10 PM THREAD STARTER               #3 (permalink)
NamePros Regular
 
mignolo's Avatar
Join Date: Mar 2007
Posts: 460
mignolo is a jewel in the roughmignolo is a jewel in the roughmignolo is a jewel in the rough
 



GREAT! Thank you very much!
????: NamePros.com http://www.namepros.com/showthread.php?t=621778

Originally Posted by qbert220 View Post
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]
__________________
RodeoArena.com for Sale, PM for Offers
mignolo is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:32 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger