1

Every image in the folder

http://www.example.com/files/thumbs

needs a redirect to

http://images.example.com/files/thumbs

I tried:

RewriteRule ^files/thumbs(.*)$ http://images.example.com/$1 [L,R=301]

but result is:

http://images.example.com//test.jpg

instead of

http://images.example.com/files/thumbs/test.jpg

thank you

labu77
  • 605
  • 1
  • 9
  • 30

1 Answers1

0

You need to capture full request URL:

RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^(files/thumbs/.*)$ http://images.example.com/$1 [L,R=301,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Hi, thank you very much. I made a test but when I open http://images.example.com/files/thumbs/test.jpg its saying: to many redirects. I guess there is something wrong. Maybe you know? – labu77 Mar 24 '15 at 11:46
  • Probably both domains are pointing to same host. See updated answer, you will need `RewriteCond %{HTTP_HOST} ...` as well. – anubhava Mar 24 '15 at 11:49
  • Hi, thank you very much. Yes both pointing to the same host. Now images.example.com/files/thumbs/test.jpg is working but now its saying to www.example.com/files/thumbs/test.jpg there are to many redirects. Thank you again for help, if possible? – labu77 Mar 24 '15 at 11:54
  • 1
    sorry, as always, cache issue ;)...works like a charm now. you are the htaccess hero. I see your picture every when there is a htaccess question on stack ;) – labu77 Mar 24 '15 at 11:58
  • I moved now with the subdomain to a CDN (different host) . Would you please give me the first redirection as a comment again? thank you so much – labu77 Mar 25 '15 at 10:45
  • Thank you very much. I am still having this problem: "too many redirects". This is my rule I use. Is this correct? RewriteRule ^(files/thumbs/.*)$ http://images.example.com/$1 [L,R=301,NC] (images.example.com) is now a CDN CName URL with different IP thank you again for help – labu77 Mar 26 '15 at 17:55
  • Not sure, too many redirects mean both domains are probably still on same server. You better keep `RewriteCond` in that case. – anubhava Mar 26 '15 at 17:57
  • same with rewritecond. image.example.com is 100% setted with cname to a different cdn location. maybe this is the problem? when you have anything that I can try, feel free to offer. thank you very much – labu77 Mar 26 '15 at 18:23
  • I would suggest opening a new question with more details and you will get better help with all experts on SO. – anubhava Mar 26 '15 at 18:30
  • done, please read what I wrote in important. Maybe this helps you. http://stackoverflow.com/questions/29287374/301-redirect-all-images-to-cdn – labu77 Mar 26 '15 at 19:39