Forum Moderators: phranque

Message Too Old, No Replies

*.jpg url rewriting, confirmation

         

Grimmjow

3:20 pm on Mar 7, 2010 (gmt 0)

10+ Year Member



Are those RRs ok to rewrite old urls from an old script to a new one I've moved recently?

RewriteEngine On
RewriteRule ^photos/(?:original|large|medium)/(.*)\.jpg$ pictures/$1.jpg
RewriteRule ^photos/(?:small|thumb)/(.*)\.jpg$ thumbnails/$1.jpg
RewriteRule ^photos/show/[0-9]+/[0-9]+/?$ index.php

In the old server I had several sizes, hence the original, large, medium, small and thumb folders. In the new server I only have pictures and thumbnails.

The last rule is for redirecting an invalid old style url.

Could be those ruls be optimized in some way?

Thank you.

g1smd

7:08 pm on Mar 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have used the word "rewrite" and the word "redirect" in the question. They are two different things; which one do you want?


To answer this, we need four pieces of information.
- what is the old URL for the content?
- what is the new URL for the content, or is the URL not changing?
- what is the old internal server location for the content?
- what is the new internal server location for the content, or is the internal location not changing?

All of the rules need the [L] flag added.

Redirects also require the protocol and domain name to be added to the target, and the [R=301] flag added to the end of rule. Rewrites must not have any of those things, other than the [L] flag that is.

Grimmjow

3:27 pm on Mar 8, 2010 (gmt 0)

10+ Year Member



The first twos are rewrites.
The third is a redirect.

With your info they should look like this:

RewriteRule ^photos/(?:original|large|medium)/(.*)\.jpg$ pictures/$1.jpg [L]
RewriteRule ^photos/(?:small|thumb)/(.*)\.jpg$ thumbnails/$1.jpg [L]
RewriteRule ^photos/show/[0-9]+/[0-9]+/?$ index.php [R=301,L]

For the images there was a change of paths, so that an old:
/photos/original/pic.jpg
Should be rewritten to:
/pictures/pic.jpg
(same appllies to /original/large/ and /original/medium/)

Same rule for /photos/small,/photos/thumb -> /thumbnails

The last redirect is to take into account invalid links, to let redirect them to the homepage of the new script.

g1smd

7:48 pm on Mar 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When you say 'path' I have no idea whether you are talking about the path part of the URL, or the server internal path to the file.

Redirects should include protocol and domain name in the target URL. Redirects should be listed before rewrites. Never redirect to a named index file. The URL should end with a trailing slash.

There are major duplicate content issues with your code. Multiple URLs can serve the same content. That is an SEO disaster waiting to happen.

Grimmjow

8:47 am on Mar 9, 2010 (gmt 0)

10+ Year Member



I know I did good asking for help here :)

In this case URL path is the same of filesystem folders. The difference from the old script I was using from the new is that the old one used to store different formats of the pictures in many more folders than the new one. So I have to map 5 older folders to 2 new ones.

Thanks for the info about redirects.

This should be final so:

RedirectMatch 301 ^/photos/[0-9]+/[0-9]+/?$ http://www.example.org/
- or -
RewriteRule ^photos/show/[0-9]+/[0-9]+/?$ http://www.example.org/ [R=301,L]

RewriteRule ^photos/(?:original|large|medium)/(.*)\.jpg$ pictures/$1.jpg [L]
RewriteRule ^photos/(?:small|thumb)/(.*)\.jpg$ thumbnails/$1.jpg [L]

g1smd

9:13 am on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"So I have to map 5 older folders to 2 new ones." is still unclear to me as to whether we are talking about URLs as used out on the web, or folders located inside the server. These things are related but are not the same thing.

Is this what you want to do?

Option 1:
- Internally rewrite multiple old URL requests to map to the new script paths inside the server; so that most old URLs continue to work by directly supplying content.

Option 2:
- Externally redirect requests for old URLs to the new URLs so that old URLs are updated to new URLs.
- Internally rewrite requests for new URLs to the new script paths inside the server, with only one URL per image being able to directly show content.

Option 1 creates duplicate content, and appears to be the option you have chosen.

Option 2 is what I think you should be using, and the code is quite a bit different to what you have presented here.

Grimmjow

5:41 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



Yes actually "Option 1" is the one running.

Using Option 2, I'm not sure if another website using old URLs to the image will continue to show the picture. Considering that that website is never gonna update the old URLs in its contents. For this reason I opted for the internal rewrite only.

g1smd

6:19 pm on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The redirect is the correct option.

- Client clicks link with old URL in it.
- Server tells client to request new URL.
- Client requests new URL.
- Server delivers the content.

Grimmjow

7:15 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



Does it work if the link is not "clicked" but used as a src of an <img />?

If yes, is this the correct line to add into the .htaccess?

RewriteRule ^photos/(?:original|large|medium)/(.*)\.jpg$ http://www.example.org/pictures/$1.jpg [R=301,L]

Thanks for your time.

jdMorgan

7:43 pm on Mar 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It shouldn't be an issue either way if you are not concerned with getting or keeping these image URLs ranked in image search engines. In that case, the internal rewrite may be acceptable and is more efficient, as it does not require the client to re-request the image.

You're apparently using PCRE patterns (the "?:" part) and that may not work as expected on all servers. I'd suggest tweaking that rule to
 RewriteRule ^photos/(original|large|medium)/([^.]+)\.jpg$ http://www.example.org/pictures/$1.jpg [R=301,L] 

-or-
 RewriteRule ^photos/(original|large|medium)/([^.]+)\.jpg$ /pictures/$1.jpg [L] 

depending on which of "option 1 or 2" you choose to use.

Jim

Grimmjow

7:23 pm on Mar 20, 2010 (gmt 0)

10+ Year Member



I'm staying with the option 2. I should use $2.jpg then? %1 should refer to (original|large|medium) that I'm not interested into?

jdMorgan

10:42 pm on Mar 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, yes, that's correct -- Use $2.

Jim

Grimmjow

12:38 am on Mar 22, 2010 (gmt 0)

10+ Year Member



Thanks.