开发者

Htaccess Image redirect to specific resize directory

Hopefully someone here can point me in the right direction as htaccess is driving me crazy at the moment.

What i am trying to achieve is an automatic redirect for certain images

Currently I use jquery to replace the image src. The reason for this is the new resized images are in a different directory.

The problem with this method is every time we refresh we have to wait for the dom to fully load. And I see this is possible with htacce开发者_StackOverflow社区ss.

Redirect /my-domain.com/images/image1.png /my-domain.com/images/resized/image1.png

Currently this works, but for over 100 images I really need to find a dynamic solution for this

I tried the following which obviously failed.

RewriteRule ^/my-domain.com/images/(.*) /my-domain.com/images/resized/(.*) [R=301,L]

the resized directory has several directory's so the rule needs to apply to all child directories. Although it's not a big problem to list all the directories as long as I don't list all images.

hopefully I am missing something simple here, also I wanted to make sure the redirect will not effect SEO?

maybe there is an alternative solution with htaccess?


This is a bit of a messy way to handle images - across multiple folders - but, if that's how you want to manage it, fair enough.

From the above, I understand that:

  • There are some images within the /images/resized/ folder
  • There are also some images within subfolders of the same
  • You want to be able to call a URL within the /images/ folder and have it transcribed to the /images/resize/ folder (with the same end)

In the webroot's .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/images/
RewriteCond %{REQUEST_URI} !^/images/resized/
RewriteRule ^images/(.+)$ /images/resized/$1

Tested OK with this htaccess tester.

"I wanted to make sure the redirect will not effect SEO?" Filenames are not as important for SEO as alt tags and titles. There should be no change to the SEO stance of your site as a result of this change.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜