homepage Welcome to WebmasterWorld Guest from 54.161.236.92
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Duplicate Site Redirects.
urls need to support 4 URL vars
mainebob




msg:4172471
 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:
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

 

jdMorgan




msg:4172510
 9:06 pm on Jul 18, 2010 (gmt 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

mainebob




msg:4172540
 11:47 pm on Jul 18, 2010 (gmt 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

jdMorgan




msg:4172611
 3:52 am on Jul 19, 2010 (gmt 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

mainebob




msg:4172618
 4:16 am on Jul 19, 2010 (gmt 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...]

jdMorgan




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

g1smd




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

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

How should that request be handled?

mainebob




msg:4173024
 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
old.com/adir/index.php?w=123
or alternately
old.com/adir/?w=123 ['cause it's "index"

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved