-1

I want to be able to add some code to my .htaccess file that allows me to generate differently sized images by adding "?w=100&h=100" after the URL. Does anyone know what the code is to accomplish this? I have asked this question before, but I wasn't clear enough. I hope this is more understandable.

Ryder Cragie
  • 145
  • 1
  • 9

1 Answers1

2

That's not something that a .htaccess file on its own can achieve; it's just a configuration file for features built into the Apache web server. It's commonly used to manipulate the URLs requested, because that's one of the features of Apache - the "rewrite module". Manipulating images is not a feature of Apache, as can be seen by looking through the list of modules in the documentation.

To do what you're asking, you need some kind of program running on the server - PHP, Ruby, Python, etc - that will do the actual resizing, probably storing the results at different sizes somewhere so they don't have to be regenerated every time. For instance, in PHP you would probably use functions in the gd extension.

Once you've got the program working, you can use mod_rewrite to point pretty URLs at it.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • This is what I am referring to: https://media.discordapp.net/attachments/900350448001757204/976126937636425779/IMG_4073.png?width=1920&height=1080 Change the sizes at the end of the URL and you'll see that it works. – Ryder Cragie May 17 '22 at 14:20
  • 1
    @RyderCragie Yes, because that server is running a script to look at the URL parameters, and do some resizing, not because they know some secret .htaccess trick. They may not even be running Apache. Just as there is no line you can put in .htaccess that will make your website into Facebook, or Stack Overflow; that's all down to the application code that's running on the server. – IMSoP May 17 '22 at 14:45