Welcome to WebmasterWorld Guest from

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)

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

so typing:
takes the viewer to the old site

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 Jul 18, 2010 (gmt 0)

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

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.

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

Hi Jim,
The combinations we need are


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

-Bob O
3:52 am on Jul 19, 2010 (gmt 0)

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

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]

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

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


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:
2:07 pm on Jul 19, 2010 (gmt 0)

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

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.

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

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

@mainebob What if a user requests:

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

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

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

Featured Threads

Hot Threads This Week

Hot Threads This Month