Frank
Frank

Reputation: 1864

.htaccess fake image

I currently have a system where I can go

<img src = "http://www.mydomain.com/assets/thumbnail.php?url=website_url_here/"/>

But the issue is, is the browser wont cache it because I will have multiple of these images on one page but just changing thr url variable.

So what I would like to do is use .htaccess to turn the url into

<img src = "http://www.mydomain.com/assets/thumbnail/website_url_here.png"/>

How could this be done?

Upvotes: 0

Views: 260

Answers (1)

Jon Lin
Jon Lin

Reputation: 143896

You can add some mod_rewrite rules in the htaccess file in either your document root or in your assets directory. In your document root, they'd look something like this:

RewriteEngine On
RewriteRule ^/?assets/thumbnail/([^.]+)\.(png|jpe?g|gif)$ /assets/thumbnail.php?url=$1.$2 [L,NC]

Or if the htaccess file is in the assets directory:

RewriteEngine On
RewriteBase /assets/
RewriteRule ^thumbnail/([^.]+)\.(png|jpe?g|gif)$ thumbnail.php?url=$1.$2 [L,NC]

Upvotes: 1

Related Questions