Redirecfting all hits to a different location

S

spl2k4

I'm not quite sure how to word this exactly, but what I am trying to do
is have everything forward from one web to another.

An example may help...

The base location of the web to be forwarded is say http://firstweb,
and the web to be forwarded to is http://secondweb/somefolder

When a user goes to say http://firstweb/mypage.htm, it then forwards to
http://secondweb/somefolder/mypage.htm.

I want it to do that no matter what comes after http://firstweb...
anything after http://firstweb gets added to
http://secondweb/somefolder.

Hopefully that made sense. If anybody can suggest anything I would be
eternally grateful!!

Ryan
 
T

Trevor L.

I'm not quite sure how to word this exactly, but what I am trying to
do is have everything forward from one web to another.

An example may help...

The base location of the web to be forwarded is say http://firstweb,
and the web to be forwarded to is http://secondweb/somefolder

When a user goes to say http://firstweb/mypage.htm, it then forwards
to http://secondweb/somefolder/mypage.htm.

I want it to do that no matter what comes after http://firstweb...
anything after http://firstweb gets added to
http://secondweb/somefolder.

Hopefully that made sense. If anybody can suggest anything I would be
eternally grateful!!

Ryan

Well, you can get the location in JS as location.href, then search it for
"firstweb" and replace it by"secondweb/somefolder"

Try this
<head>
<script>
var oldloc = location.href
var newloc = oldloc.replace(/firstweb/,"secondweb/somefolder")
// alert (oldloc + " " + newloc)
location.href=newloc
</script>
</head>

You might have problems if the address is:
http://firstweb/ without a file following

Ths would change to
http://secondweb/somefolder/

If there is no default file at this location, you will get an error.

But any file such as http://firstweb/index.html
would change to http://secondweb/somefolder/index.html
 
S

spl2k4

Thanks for the reply Trevor!

That sounds workable, but it would require me to do that for ever page,
am I right? I was hoping there was an all-encompassing solution that
would do the same for every page. If not, no big deal, I am just trying
to research ways to create a smooth transition from the old web to the
new one.

Ryan
I'm not quite sure how to word this exactly, but what I am trying to
do is have everything forward from one web to another.

An example may help...

The base location of the web to be forwarded is say http://firstweb,
and the web to be forwarded to is http://secondweb/somefolder

When a user goes to say http://firstweb/mypage.htm, it then forwards
to http://secondweb/somefolder/mypage.htm.

I want it to do that no matter what comes after http://firstweb...
anything after http://firstweb gets added to
http://secondweb/somefolder.

Hopefully that made sense. If anybody can suggest anything I would be
eternally grateful!!

Ryan

Well, you can get the location in JS as location.href, then search it for
"firstweb" and replace it by"secondweb/somefolder"

Try this
<head>
<script>
var oldloc = location.href
var newloc = oldloc.replace(/firstweb/,"secondweb/somefolder")
// alert (oldloc + " " + newloc)
location.href=newloc
</script>
</head>

You might have problems if the address is:
http://firstweb/ without a file following

Ths would change to
http://secondweb/somefolder/

If there is no default file at this location, you will get an error.

But any file such as http://firstweb/index.html
would change to http://secondweb/somefolder/index.html

--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 
T

Trevor L.

Thanks for the reply Trevor!

That sounds workable, but it would require me to do that for ever
page, am I right? I was hoping there was an all-encompassing solution
that would do the same for every page. If not, no big deal, I am just
trying to research ways to create a smooth transition from the old
web to the new one.

Ryan

I can't think of any other way to redirect every page to another.

The only point in favour is that you may not have to insert the code in
every page. If you have an external.js file linked in your pages then you
can add this to it:
function redirect () {
var oldloc = location.href
var newloc = oldloc.replace(/firstweb/,"secondweb/somefolder")
location.href = newloc
}

But in each page you will need to alter
<body>
to
<body onload="redirect()">

It is possible that you can do this with a text editor, i.e. replace:
<body>
by:
<body onload="redirect()">
I think it would still be a page-by-page exercise, but some text editors
retain the search and replace details when many pages are open. You just
switch to another page and you don't have to re-enter the details.

If you dont have a file such as external.js linked in every page, then you
may be able to add the link with a text editor as well
The link is: <script type="text/javascript"
src="scripts/external.js"></script>

So it may be possible to replace:
</head>
by:
<script type="text/javascript" src="scripts/external.js"></script></head>
 
T

Trevor L.

BTW,

In my email program, what I wrote doesn't appear properly
This line:
var newloc = oldloc.replace(/firstweb/,"secondweb/somefolder")

should be
var newloc = oldloc.replace(

Then after this it should read (no separation)
/
firstweb
/
then
,"secondweb/somefolder")

Let's see if this presents OK
 
M

MD Websunlimited

Do you have access to the server? If so then you could use a mod rewrite, search Google, to redirect all requests to the other site.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top