views:

11

answers:

2

Hi, I have some links problem and I'm trying to solve the problem using htaccess.

I have a directory that contain images, for example:

PGPHX.203.jpg
PGPHX.80.jpg
PGPHX.137.jpg
...

I want that all the links that doesn't contain a *.number.jpg at the end to be pointed to *.203.jpg, for example:

FROM: PGPHX.jpg TO: PGPHX.203.jpg
38.108.97.145/content/memberAvatars/2/QBqz6/PGPHX.jpg
http://38.108.97.145/content/memberAvatars/2/QBqz6/PGPHX.203.jpg

Just to make it clear, I have those ruls in the htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.78\.jpg$ $1\.80\.jpg [L] #size 78 no longer exists, redirect to 80

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.230\.jpg$ $1\.203\.jpg [L] #size 230 no longer exists, redirect to 203

RewriteRule defaultAvatar\.(png|jpg) defaultAvatar\.203\.jpg [L] #any defaultAvatar with no size, redirect to jpg
RewriteRule defaultAvatar\.(\d{1,3})\.png defaultAvatar\.$1\.jpg [L] #redirect any default avatar png, to jpg.

Thanks for the help, Eldad.

A: 

Here's my previous suggestion, updated to reflect your comment:

RewriteRule ^(\w+)\.(jpg|png)$ $1.203.jpg

This assumes that all filenames which you want to rewrite are of the form (word characters).(jpg|png). If there are other possibilities you have to deal with, the pattern will need tweaking.

EDIT: More generally, I suppose you could try

RewriteCond %{REQUEST_URI} !\d+\.(jpg|png)$
RewriteRule ^(.+)\.(jpg|png)$ $1.203.jpg
David Zaslavsky
Thanks that but won't work.The file name can conatain numbers and underscore ([A-Za-z0-9_]+) - but still, that wont work.
Eldad
@Eldad: Why not? I think you need to be more clear about what your requirements are.
David Zaslavsky
A: 

Well this is working for me:

RewriteRule ^(.*)\/([A-za-z0-9-_]*)\.jpg $1\/$2\.203\.jpg [NS,L] #filename with no size - redirect to 203
Eldad