Welcome to WebmasterWorld Guest from 54.163.52.98

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect image path

     

sam222

12:22 pm on Jun 19, 2013 (gmt 0)



For image path redirect, I am trying to do below but no success. Can i have any help on it please:

URL is like:
example.com/dir1/dir2/dir3/dir4/imagefilename.jpg


RewriteRule ^/dir1/dir2/dir3/dir4/(.*)$ /images/test/dir3([^/]+\.(gif|png|jpg) [R=301,L]

where i want to redirect example.com/dir1/dir2/dir3/dir4/imagefilename.jpg to example.com/images/test/dir3/imagefilename.jpg

phranque

12:33 pm on Jun 19, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



^/dir1/dir2/dir3/dir4/(.*)$

if your RewriteRule is in the .htaccess file in the document root directory, the leading slash will be stripped and your Pattern string should reflect that.

/images/test/dir3([^/]+\.(gif|png|jpg)

since it's an external redirect, include the full protocol and hostname in the Substitution string.
also, since it's a substitution string and not a regular expression (pattern), you should have any capture groups or escape sequences.
you probably do want to use a backreference to reuse the captured file name.

sam222

12:48 pm on Jun 19, 2013 (gmt 0)



I have tried to do but no success. Could you please further help:

RewriteRule ^http://www.example.com/dir1/dir2/dir3/dir4/(.*)$ http://www.example.com/images/test/dir3([^/]+\.(gif|png|jpg) [R=301,L]

phranque

12:55 pm on Jun 19, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



the full protocol and hostname should be in the Substitution string, but not in the Pattern string.

the url you are testing with that Pattern will have the leading slash stripped.

you shouldn't have any regular expression-type junk in the Substitution string, but you should have the backreference to the captured image file name.

sam222

1:47 pm on Jun 19, 2013 (gmt 0)



RewriteRule ^dir1/dir2/dir3/dir4/(.*)$ http://www.example.com/images/test/dir3/$1 [R=301,L]

This works now fine but it doesn't display images now and goes in loop. Might be because of URL rewrite rule:

RewriteRule ^images/test/dir3/([^/]+\.(gif|png|jpg))$ /dir1/dir2/dir3/dir4/$1/$2 [L]

lucy24

6:28 pm on Jun 19, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Wait a minute. What "URL rewrite rule"? If image URLs are already being rewritten, why bother to redirect them? Simply change the rewrite to point to the image's new home.

If your rules are really as posted, you've got a pure loop:

request a redirects to b, which in turn rewrites to a.

To stop the loop, the external redirect needs a preceding RewriteCond that says "only do this if %{THE_REQUEST} was for ^/dir1/dir2 et cetera". In other words, only redirect requests that haven't already been rewritten.

And, as with any redirect, fix the code that asks for the wrong URL. This is easier with images than with pages, because you only have to tweak things on your own site.

sam222

6:38 pm on Jun 19, 2013 (gmt 0)



If image URLs are already being rewritten, why bother to redirect them? Simply change the rewrite to point to the image's new home.


As images have been read by Google and if i don't do URL redirect for images i am afraid i will lose ranking in Google SERP for images. I might be wrong if you can correct me further please.

Could you please write me more details how can i make this condition for rewrite if you can write me an example please.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month