Apache Redirect/ReWrite for redirecting old->new domains?

Apache Redirect/ReWrite for redirecting old->new domains?

Post by Frampton Steve » Thu, 08 Jul 1999 04:00:00



Hello:

I'm having some difficulty getting Apache to redirect page requests with
an informative message.  My place of employment is moving from their old
domain name to a new one.  We now have both of these domain names active,
both of which point to the same server.  Although we will be phasing out
the old address very soon, people continue accessing the pages at the old
address, hence the reason for the redirect.

Putting something like <META HTTP-EQUIV="refresh"
"CONTENT=05;URL=http://newdomain.com/newpage"> in all our pages is not
an optimal solution because (a) there are hundreds of pages that would
need to be updated, (b) this solution doesn't display an informative
message before the redirect, and (c) Apache provides a better solution.

I've tried using a RedirectMatch:

RedirectMatch http://olddomain.com/~test/(.*) http://newdomain.com/~test/$1

Unfortunately, any pages access in .../~test do not redirect, but access
from the olddomain.com.

I've also tried a RewriteRule:

RewriteRule http://olddomain.com/~test/.* http://newdomain.com/~test/$1 [R=301L]

This also doesn't seem to work.

Is there a way to redirect visitors to all pages (or some pages in a
given directory or directories) with an informative message that appears
for about 5 seconds from the old access point to the new one?  (Notice I
say "access point" instead of "old page to new page" -- since the pages
are the _same_ as the old and new addresses point to the same server)

Thanks in advance for any assistance.

--------------< LINUX: The choice of a GNU generation. >--------------

 
 
 

Apache Redirect/ReWrite for redirecting old->new domains?

Post by Joshua Sliv » Thu, 08 Jul 1999 04:00:00



Quote:> Hello:
> I'm having some difficulty getting Apache to redirect page requests with
> an informative message.  My place of employment is moving from their old
> domain name to a new one.  We now have both of these domain names active,
> both of which point to the same server.  Although we will be phasing out
> the old address very soon, people continue accessing the pages at the old
> address, hence the reason for the redirect.
> Putting something like <META HTTP-EQUIV="refresh"
> "CONTENT=05;URL=http://www.veryComputer.com/;> in all our pages is not
> an optimal solution because (a) there are hundreds of pages that would
> need to be updated, (b) this solution doesn't display an informative
> message before the redirect, and (c) Apache provides a better solution.

I think that your syntax is a little off. Check the Apache docs for
the relevant directives.  What I would do is something like

Rewri*gine On
RewriteRule ^/~test/(.*) /redirector.shtml/$1

Then configure /redirector.shtml as an SSI parsed document looking
something like

<HTML>
<HEAD><TITLE>This page has moved</TITLE>
<META HTTP-EQUIV="refresh"
CONTENT="05;URL=http://www.veryComputer.com/~test/<!--#echo var="PATH_INFO" -->">
<BODY>
<H1>This page has moved</H1>

<P>The new location is <A HREF="http://www.veryComputer.com/~test/<!--#echo
var="PATH_INFO" -->">here</A>.  You will be redirected automatically
in 5 seconds.  Please update your bookmarks.

</BODY>
</HTML>

This is completely untested, and probably has errors, but it should
get you started.  You could also use a cgi script instead of the SSI
page if you prefer.

 
 
 

Apache Redirect/ReWrite for redirecting old->new domains?

Post by Frampton Steve » Fri, 09 Jul 1999 04:00:00


: I think that your syntax is a little off. Check the Apache docs for
: the relevant directives.  What I would do is something like
:
: Rewri*gine On
: RewriteRule ^/~test/(.*) /redirector.shtml/$1

Thanks for the tip -- will I likely be able to catch accesses going to
oldserver.com using something like ^/oldserver.com/~test/(.*)?

Cheers...

--------------< LINUX: The choice of a GNU generation. >--------------

 
 
 

Apache Redirect/ReWrite for redirecting old->new domains?

Post by Joshua Sliv » Fri, 09 Jul 1999 04:00:00




> : I think that your syntax is a little off. Check the Apache docs for
> : the relevant directives.  What I would do is something like
> :
> : Rewri*gine On
> : RewriteRule ^/~test/(.*) /redirector.shtml/$1
> Thanks for the tip -- will I likely be able to catch accesses going to
> oldserver.com using something like ^/oldserver.com/~test/(.*)?

No.  Put the RewriteRule's in a <VirtualHost> or test for the
correct host in a RewriteCond instead.

--
Joshua Slive

http://www.veryComputer.com/~slive/

 
 
 

1. : Weird ">" redirect behavior vs. ">>" redirect behavior

Hopefully, someone has already seen this and knows whats up.

Simple script myscript.sh:

#!/bin/sh
i=1

date
while [ 1 ]; do
   echo "Count - ${i}"
   cat /etc/system
   i=`expr ${i} + 1`
   sleep 5
done

Run it as:

nohup sh myscript.sh > /tmp/myscript.log &

Let it run for a while.  Then run:

grep Count /tmp/myscript.log | wc -l
ls -l /tmp/myscript.log
cat /dev/null /tmp/myscript.log
ls -l /tmp/myscript.log
ls -l /tmp/myscript.log
ls -l /tmp/myscript.log
grep Count /tmp/myscript.log | wc -l

The file size info on my system (Solaris 8) for the /tmp/myscript.log
is zero at first and then goes right back to where it was but a bit
more when the next iteration of the cat command output /etc/system.

Also, the first grep..wc -l command shows how many times the script
has basically looped.  The second grep will show only a couple.  This
shows that the inode is saying the file contains everything is always
did but the grep command is saying it only contains up to some of
point a buffer - maybe the output file descriptor buffer?  I'm
guessing I'm not a programmer

If you change the ">" to a ">>" with your nohup , it works as
expected. The file is zeroed out and the inode info shows it growing
as you would expect it to.

What's the differences between ">" and ">>" that makes this happen?
Running the script with ksh does the same thing.

Looks like a bug to me.

--
........................................................
......... ..- -. .. -..- .-. ..- .-.. . ... ............
.-- .. -. -... .-.. --- .-- ... -.. .-. --- --- .-.. ...

Sean O'Neill

2. X probs with DISPLAY

3. Apache Rewrite domain.com->index.php domain.org->index2.php

4. Diffs between Intel & AMD 486 CPUs

5. Apache rewrite and redirect

6. CPU idle time

7. Apache: Precedence of rewrite vs redirect

8. facetterm Clone

9. Apache mod rewrite without redirecting

10. apache is redirecting virtualhosts to old addresses

11. Using .htaccess to redirect to new domain

12. Advice on redirecting 100 domain names in Apache

13. Win 9x -> pptp over internet -> Linux NAT and redirect -> NTserver