views:

31

answers:

4

How can I mask so all instances of www.oldsite.com are replaced with www.newsite.com

example:

I'd like to replace: http://www.oldsite.com/home/b.jsp?id=9912&ln=115-991632

with www.newsite.com/home/b.jsp?id=9912&ln=115-991632

+1  A: 

You can do this in Apache with the Redirect directive:

<VirtualHost *:80>
    ServerName www.oldsite.com
    Redirect permanent /home/ http://www.newsite.com/home/
</VirtualHost>
Greg Hewgill
A: 

Well, if you only want to replace that page, you can create a .htaccess file with this content:

Redirect 301 /b.jsp?id=9912&ln=115-991632 http://www.newsite.com/home/b.jsp?id=9912&amp;ln=115-991632

That's all I can think now. You should upload it to your /home directory.

Veehmot
Thank you, but what if I have 100 or so old links, is there a way to tell it to replace all "oldsite" with "newsite"?
drew
A: 

Try this one:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
Sudhir
how does that tell it where www.oldsite.com is?
drew
A: 

If you want to do at the application level, just print a location header:

#!/bin/bash
echo 'Location: http://www.newsite.com'

To make it even better, you can place that cgi script at "home" (replace the directory with a script) and use the $PATH_INFO variable to do the correct thing

#!/bin/bash
echo 'Location: http://www.newsite.com/$PATH_INFO'
bukzor