Photo
- - - - -

htaccess redirecting an image


  • Please log in to reply
3 replies to this topic

#1 Chapman

Chapman

    Moderately Sized Orange

  • Members
  • PipPipPip
  • 124 posts

Posted 03 April 2012 - 09:15 PM

I have recently updated an image on my site. Unknowingly this has caused a problem for people looking for said image via search engines—how was I to know it was so popular? Being that I have updated it WordPress has placed it in a new directory. The directories for media in WordPress are organized by year and month, i.e. /2012/04/image.jpg I have attempted to create an htaccess redirect of said image but it did not work. This i must attribute to my not knowing much about coding such things and not that a solution exists.

If I want to redirect http://mysite.com/wp...1/coolimage.jpg to http://mysite.com/wp...4/coolImage.jpg what would the proper htaccess entries be?
  • 0

#2 billzo

billzo

    Very Large Orange

  • Members
  • PipPipPipPipPip
  • 658 posts

Posted 04 April 2012 - 10:54 AM

Did you try any of the online htaccess rule generators?

http://seo-website-d...irect-Generator

# Needed before any rewriting
RewriteEngine On

### Built using the .htaccess 301 Redirect Generator from Web Site Advantage
### http://seo-website-designer.com/HtAccess-301-Redirect-Generator
### Place after 'RewriteEngine On' and before any CMS specific rewrite rules

## 301 Redirects
# 301 Redirect 1
RewriteCond %{HTTP_HOST}  ^mysite\.com$ [NC]
RewriteCond %{QUERY_STRING}  ^$
RewriteRule ^wp-content/uploads/2011/01/coolimage\.jpg$ http://mysite.com/wp-content/uploads/2012/04/coolImage.jpg? [R=301,NE,NC,L]

You can try that and see if it works.
  • 0
Posted Image
Click here to sign up with A Small Orange today!

ASO servers are fast and they offer excellent support for a great price. ASO is the BEST host around!

I have been with ASO since June 2007 and recommend this host highly. ASO has only gotten better over time. There is no better testimonial about the quality of service of a webhost than a long-term customer like me. Don't make a frustrating and time-consuming mistake of signing up with any other webhost. ASO is what you need.

Whether you are hosting a small hobby site like a Wordpress blog, a serious business website, or need a Dedicated Server, VPS or Cloud hosting, ASO has superior quality professional-level hosting packages for you.


View A Small Orange Hosting Plans


$$$ Coupon codes to save you money $$$

Code to save $5: saveme$5
Code to save 15%: saveme15%


Enter the coupon codes when ordering to get your discount. Save $5 or 15% off your initial order.

Sign up with A Small Orange today! You will be glad you did.
Posted Image

#3 Chapman

Chapman

    Moderately Sized Orange

  • Members
  • PipPipPip
  • 124 posts

Posted 04 April 2012 - 07:59 PM

Did you try any of the online htaccess rule generators?

You can try that and see if it works.


I did not, before now. I reentered with the actual addresses which turned out the same code but it did not work. I even tried with opening and closing adding <IfModule mod_rewrite.c> Still nothing.

How do I tell google the image has moved or how do I move the image back to the original location and update the database?
  • 0

#4 IBBoard

IBBoard

    Massive Orange

  • Volunteer Moderators
  • PipPipPipPipPipPipPip
  • 4,881 posts

Posted 05 April 2012 - 02:44 AM

It is a more advanced way of doing it, but you could use SSH access and create a symbolic link from the old location to the new. It'd mean people would see both the new and old image, rather than being redirected to just the new one, but it'd mean the old version would be updated as well (and it *might* play more nicely with some browsers - I'm not sure if any browsers can't handle 3XX status codes on <img> tags). If you've not got it already, ask ASO for SSH access, log in, delete the old image and then run:
ln -s /home/you/path/to/wp-content/uploads/2012/04/coolImage.jpg /home/you/path/to/wp-content/uploads/2011/01/coolimage.jpg

With the code Billzo gave you, did you Ctrl+F5 the image to force a refresh and a new request to the server? It could be that you've still got it cached and so your browser never made a new request and so wasn't told that the image had moved. You could also remove the two RewriteCond lines, as they're both optional (but will help in some specific circumstances).
  • 0
The more information you provide, the better answer the community can give.

*** Sign up at ASO with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users