Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help write some JavaScript - URL redirects with rewrites

Status
Not open for further replies.

MrBrainz

Technical User
Jan 31, 2004
2
GB
Hi there,

I hope someone can help me.

I'm porting a blog from an extrememly restrictive provider onto a self-hosted solution. I don't want to lose bookmarked direct traffic and inbound links. The trouble is the restrictive blog provider doesn't allow server-side scripting or access to .htaccess files.

I've come up with an ingenious way of redirecting the traffic using a find and replace feature on the blog provider. I just need a script that will do the trick.

I need to:

1. Take the URL the page is on... (jttp://blogname.swagblogs.com/my_weblog/2008/09/crappy-name.html)
2. ...and replace the base with my new domain... (jttp://blog.goodblog.com/2008/09/crappy-name.html)
3. ...then lose the .html extension... (jttp://blog.goodblog.com/2008/09/crappy-name)
4. ...then send the browser onto the new URL

Caveats:

1. I intend to replace instances of </p> with <script type="text/javascript" src="scriptname.js"></script>, so really I need the script to still work when there are multiple instances of it on the same page.
2. The .html extension may not always be present


Can anyone help me please? I realise this is cheeky but I'm at my wit's end with this crappy blog hoster and I regret ever going with them!
 
You could take the URL that the page is on and append that as a GET param on your new provider hostname... and then use .htaccess rules to redirect correctly.

Original blog page:
Redirect to:

And then the .htaccess could process that to redirect to a more appropriate URL based on whatever scheme you want.

So... back to the other part... try something like this:
Code:
if (window.redirect != undefined) {
  window.redirect = true;
  window.location = '[URL unfurl="true"]http://www.coolblog.net/?url='[/URL] + window.location.href;
}

It might work!

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Jeff that is frigging genius!

Any idea on the correctly formatted mod rewrite I'd need?

Thanks very much.

Greg
 
I'm by no means an expert on this... but try something like:
Code:
RedirectMatch 301 ^/.*url=http://www.example.com/(.*)\.html$ [URL unfurl="true"]http://www.coolblog.net/$1[/URL]

Maybe someone else can chip in to verify that?

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top