Welcome to WebmasterWorld Guest from 54.242.165.26

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Duplicate Site Redirects.

urls need to support 4 URL vars

     
7:20 pm on Jul 18, 2010 (gmt 0)

New User

5+ Year Member

joined:July 18, 2010
posts: 5
votes: 0


We are slowly moving from site old.com to new.com and for a couple of months we want to duplicate access:

so typing:
new.com/adir/?a=1&b=2&c=3&d=4
takes the viewer to the old site
old.com/adir/?a=1&b=2&c=3&d=4

Also, sometimes viewers come with no url vars or less
than four and the redirect needs to work for other
subdirectories too.

Is there a Mod Rewrite that will handle this?

Sites are linux based.

-Bob O
9:06 pm on July 18, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


If the behaviour of the server depends on the presence or absence of those variables, or on specific values of those variables, then you will need five rules, one for a=1&b=2&c=3&d=4, one for a=1&b=2&c=3, one for a=1&b=2, one for a=1, and finally, a last rule for no query string at all.

If you need to handle all possible permutations of variable presence or absence, then you'll need up to sixteen rules.

If the script can handle being called with one or more variable names having no value, then the rules can be 'compressed' a bit. An example would be a request like /adir?a=1&b=2&c=&d= where the values for c and d are blank. Some scripts handle that with aplomb, while others simply halt and catch fire.

And if *all* permutations of query strings are to be redirected, then you likely need only one rule, triggered only by the presence of "/adir" in the requested URL.

So, let's nail down the specific requirements first... What URLs+queries do you wish to redirect, and what URLs+queries do you not want to redirect? The more examples or more detailed the description, the better.

Here we get into 'set theory' and 'URL taxonomy' as implied by the use of regular expressions supporting a very wide range of matching options... Sets, subsets, URL-path-parts, subpattern-matching, back-references... Simple text-matching isn't always so simple... :)

Anyway, requirements specification first, coding later.

Jim
11:47 pm on July 18, 2010 (gmt 0)

New User

5+ Year Member

joined:July 18, 2010
posts:5
votes: 0


Hi Jim,
The combinations we need are

new.com
new.com/?w=123
new.com/?w=123&x=&y=&z=

Where x, y, z, may not have vars
I think that reduces the posibilities to 3

Thanks!
-Bob O
3:52 am on July 19, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Are these two sites separately hosted, or are they co-hosted in the same server filespace?

This determines whether the code needs to evaluate the currently-requested hostname before deciding to redirect or not.

Your second example is inconsistent with the first, as "/adir" has apparently vanished. Such details are critical.

The following code meets the requirements of your second example, assuming separate domain hosting, and assumes that the code will be placed in .htaccess or in a server config file within a <Directory> container.

It further assumes that you already have other working rewriterules -- that is, that Apache mod_rewrite is enabled and that the rewrite engine has already been started.

RewriteCond %{QUERY_STRING} ^(w=123(&x=[^&]*&y=[^&]*&z=[^&]*)?)?$
RewriteRule ^$ http://www.old.com/ [R=302,L]

Jim
4:16 am on July 19, 2010 (gmt 0)

New User

5+ Year Member

joined:July 18, 2010
posts:5
votes: 0


Thanks, Jim, Good pickup...
Here is the revised list

new.com
new.com/?w=123
new.com/?w=123&x=&y=&z=
new.com/adir
new.com/adir/?w=123
new.com/adir/?w=123&x=&y=&z=

Two Different servers.
The old server has rewrite working...
used for joomla and drupal that are
also on the site.

Running Apache 2.2.13
with full list of mods here:
[pair.com...]
2:07 pm on July 19, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Then make "adir/" optional in the rule pattern:

RewriteCond %{QUERY_STRING} ^(w=123(&x=[^&]*&y=[^&]*&z=[^&]*)?)?$
RewriteRule ^(adir/)?$ http://www.old.com/ [R=302,L]

This rule now 'drops' the "adir/" path part when it redirects, sending all requests to just www.old.com/ and not www.old.com/adir

If this is not what is desired, then add "$1" to the end of the RewriteRule's substitution URL

Put this rule above any internal rewrite rules in the existing file -- that is, put it above the joomla and drupal rewriterules.

BTW, the Joomla code, if straight out of the box and unmodified, could likely due with some improvements that will increase server performance -- often quite noticeably. I'm not sure about the Drupal code, but the stock Joomla code unnecessarily invokes slow and inefficient filesystem checks, which could easily be avoided.

Jim
2:47 pm on July 19, 2010 (gmt 0)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


@mainebob What if a user requests:
new.com/adir/index.php?w=123


How should that request be handled?
9:01 pm on July 19, 2010 (gmt 0)

New User

5+ Year Member

joined:July 18, 2010
posts:5
votes: 0


Thanks jim!
Hi g1smd,
> What if a user requests:
> new.com/adir/index.php?w=123

That should go to
old.com/adir/index.php?w=123
or alternately
old.com/adir/?w=123 ['cause it's "index"
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members