Solved

Htaccess code for 301 redirect of all images in image folder to other domain

Posted on 2012-03-15
9
510 Views
Last Modified: 2012-08-14
Hello

A cartoonist friend is moving a portion of his site to another domain.

He currently has lots of fans who are linking to his cartoons  (animated gifs) from places such as facebook, etc.

He doesn't want to have any of the images on his current domain, so -- if possible -- I want to put a htaccess file in his image directory pointing (310??) to an image folder in his  other domain -- where I will move the images to.  I will delete all of the images in the old domain image folder.

Is this possible with htaccess?

Thanks

Rowby
0
Comment
Question by:Rowby Goren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 7

Expert Comment

by:torakeshb
ID: 37727612
0
 
LVL 78

Expert Comment

by:arnold
ID: 37727820
Yes, you would use a redirect with a match.
The problem is that whether it is redirected or accessed on the current domain the viewer will not know the difference. Eventually this domain will have to be let go so all those who link tote images will have an issue either way the question, whether it is now or later.
0
 
LVL 2
ID: 37728858
You are better off catching all hits on the old domain with a php page that pops up a message and then redirects after a few seconds.  Something like "This page has moved from www.olddomain.com to www.newdomain.com, please update any links and bookmarks you used to access the site.   You will automatically be redirected in 15 seconds if this does not happen please click here."
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 9

Author Comment

by:Rowby Goren
ID: 37729516
Hi

Thanks for the comments.

The ideal solution for reasons beyond the scope of this question is the images must be moved to a different domain.

Currently thousands of visitors have  IMG links to his cartoons.   He doesn't want the IMG links to be broken.  

So it is not just a matter of redirecting a visitor to a new page, I am trying to prevent broken image IMG  links (not text links) from showing up all over the net on my friends fan pages (facebook, myspace, blogs, etc.)

Arnold, what is a "redirect with a match"  And can you give an example.

Is is an htaccess with a wildcard saying that all images in this folder on this domain are now in this new domain and folder" -- and thus preventing a broken image?

Note:  My friend will be keeping his "old" domain -- he just needs the images in his image folder to  be moved to new domain.  The images in his image folder will be deleted on his old domain.  The only thing that will be in his old image folder would be the single htaccess file -- assuming that it will work as I hope.  

Ideally the htaccess solution will have a wild card in it so that I don't have to list each of the images.  

Thanks

...Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 37729570
<img src="http://www.foobar.com/images/funny_flower.gif" alt="flower">

Open in new window


Above is an example of the code that is on fan sites all over the internet.

There is no  way to contact the thousands of fans -- so that is why I want to do the htaccess.   To prevent the broken image.

The images would be deleted from http://www.foobar.com/images/ and would be stored instead at http:// www.newdomain.com/images/


Rowby
0
 
LVL 78

Accepted Solution

by:
arnold earned 500 total points
ID: 37729733
One thing you can talk with the new host to ransfer the domain and configure the virtualhost on the new host with the old domain as an alias.
ServerAlias olddomain
serverAlias www.olddomain.com


As to the .htaccess provided override options are enabled
http://httpd.apache.org/docs/2.3/rewrite/remapping.html
redirectmatch ^/images/(.*) http:// www.newdomain.com/images/$1

#the item in (.*) is a pattern match whose matching content will be set in the variable $1 which is then appended to the new URL.

Combining the two domains to one provider might be a simpler solution.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 37729768
Hi Arnold,

The old domain cannot be combined with the new domain because my friend will be keeping the old domain-- but with totally new content on it.

I will do a test now, with an htaccess file in the old image folder

redirectmatch ^/images/(.*) http:// www.newdomain.com/images/$1

Open in new window


Should I put the above htacacess file in the image folder ?  Or add it to the root htaccess file>

Rowby
0
 
LVL 78

Expert Comment

by:arnold
ID: 37729834
Yes, in the images folder you would create a .htaccess file with the below directive.
Make sure the permissions on the .htaccess is 644 read/write owner, read group and read others.
also you have a space in the http:// www which should not be there which looks it came from my example

redirectmatch ^/images/(.*) http://www.newdomain.com/images/$1

Open in new window

                                           

You could add it to the top, but it will be queried for every access rather than only when it actually hits images.
0
 
LVL 9

Author Closing Comment

by:Rowby Goren
ID: 37729906
Thanks Arnold,

I put the htaccess file in the image folder and it works perfectly.


Rowby
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question