Forum Moderators: phranque

Message Too Old, No Replies

Rewrite dynamic to dynamic URIs

php generated links mapping to alternate php generated links

         

B16Enk

5:49 pm on Aug 31, 2008 (gmt 0)

10+ Year Member



Hi, have found this forum to be excellent so far! :)

I'm in the process of changing photo blogs, but because I'm getting around 5k hits a day I want the old URIs to map to the new ones.

Example:

http://www.example.com/displayimage.php?pos=-11 maps to:
http://www.example.com/index.php?showimage=17

Also there are two other alternate URIs for each image:
http://www.example.com/displayimage.php?pid=-11&fullsize=1
and
http://www.example.com//albums/quotes/kingquote.jpg

So far I have got this working for the first URI:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^pos=-11$
RewriteRule (.*) /index.php?showimage=29? [r=301,nc]

Is there a way to combine the request for the alternate displayimage.php?pid=-11&fullsize=1 on the same line as the ^pos=-11$ rule?
If I could also add in the kingquote.jpg then I would be 'cooking on gas' as they say.

Thanks.

Rog.

g1smd

7:09 pm on Sep 1, 2008 (gmt 0)

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



Be aware that http://www.example.com/index.php?showimage=17 will be a duplicate of http://www.example.com/?showimage=17 too.

If it were me, I would link to the shorter URL internally, and make sure that all URLs with index.php in them are redirected to the version without it, whilst retaining all the parameters.

jdMorgan

8:18 pm on Sep 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something like this:

RewriteEngine On
#
RewriteCond $1>%{QUERY_STRING} ^displayimage\.php>(pos=-11¦pid=-11&fullsize=1)$ [OR]
RewriteCond $1 ^albums/quotes/kingquote\.jpg$
RewriteRule (.*) /index.php?showimage=29 [R=301,L]

Note that the ">" character is arbitrary/meaningless; It is used to delimit the URL-path and the query string so that they may both be matched unambiguously even when combined as shown. Also, replace the broken pipe "¦" character with a solid pipe character before use; Posting on this forum modifies the pipe characters.

If you get a lot more of these you need to redirect in the future, then there are a couple of ways to use a more "table-like" structure. But both are unnecessarily complex if you only have a handful of these URL variants to redirect.

Jim

B16Enk

8:39 pm on Sep 1, 2008 (gmt 0)

10+ Year Member



Wow.
Jim:
Does exactly what it says on the tin!
That has simplified the task for me considerably, we have around 90 images that have three URL variants (Coppermine is nice but I think it dropped the ball there....).

I'll continue my studies of the 'Definitive Guide to Apache mod_rewrite' that I have and see what other illumination I can get from it.

Thanks your help is very much appreciated!

Rog.

ps.

Anyway I can make a tiny donation to your cause?

[edited by: B16Enk at 8:42 pm (utc) on Sep. 1, 2008]