How to redirect image requests to another dir via .htaccess?

by aniya.jaskolski , in category: Third Party Scripts , a month ago

How to redirect image requests to another dir via .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by adan , a month ago

@aniya.jaskolski 

To redirect image requests to another directory using .htaccess, you can use the following code:

1
2
RewriteEngine on
RewriteRule ^images/(.*)$ /new-directory/$1 [L,R=301]


In this code snippet, any request for an image in the "images" directory will be redirected to the "new-directory" directory. You can customize this rule to fit your specific needs by modifying the directory paths and any other conditions as necessary.


Make sure to place this code in the .htaccess file in the root directory of your website. Additionally, ensure that the mod_rewrite module is enabled on your server for this to work.