开发者

htaccess NOT pattern

开发者 https://www.devze.com 2023-01-04 09:35 出处:网络
I have some links problem and I\'m trying to solve the problem using htaccess. I have a directory that contain images, for example:

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 defau开发者_如何学编程ltAvatar\.(\d{1,3})\.png defaultAvatar\.$1\.jpg [L] #redirect any default avatar png, to jpg.

Thanks for the help, Eldad.


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消