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)
^/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:
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.