Jump to content

Image URL Mod Rewrite


CMC

Recommended Posts

 

Hi,

 

I've made an image upload/view script that works nicely but now I'm trying to have the view script generate nice URL's.

i.e: instead of view.php?id=some_id have something like /images/some_id.file_extension (/images/23.gif). The files are stored in a database.

 

Does anyone know if this is possible? I've been looking around and doing a lot of reading but I haven't found anything suggesting if it's possible. I haven't tried either because I am unsure of how to approach the coding aspect. I have basic mod_rewrite knowlede but what is stumping me is how to pass the .gif part. The .gif part will not be used in retrieving the actual image, it's just there to make the URL look nice Also, everything is dynamic; so if the image was a PNG then it would be /images/24.png.

 

Am I making sense?

Link to comment
https://forums.phpfreaks.com/topic/132359-image-url-mod-rewrite/
Share on other sites

Hey CMC,

I know exactly what you're talking about and I know how you could do it.

 

Try this for your rewrite rule:

 

RewriteRule ^images/([0-9]+)\.(gif|jpg|png)$ view.php?id=$1 [L]

 

Add any other file extensions as you need them.

 

Let me know how it goes!

  • 4 months later...

I have a very similar question, only the url structure is different.

I would like to request an image of a volcano for example, stored on the server as: img/imagenumber.extension ,via 2 different urls.

 

www.mydomain.com/img/imagenumber/volcano.extension

or

www.mydomain.com/img/volcano.extension?img=imagenumber

 

I can't get a mod write to function for either case, can someone help me?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.