cplus
cplus

Reputation: 1115

Forward blogger urls to own domain urls

How can I forward all urls on my blogspot to my own domain's corresponding urls? Example:

Forward all of these:
http://example.blogspot.com/url-1.html
http://example.blogspot.com/url-2.html
http://example.blogspot.com/url-3.html

even non-existing urls
http://example.blogspot.com/non-existing-url-4.html

To these corresponding own domain:
http://owndomain.com/url-1.html
http://owndomain.com/url-2.html
http://owndomain.com/url-3.html
http://owndomain.com/non-existing-url-4.html
basically, how to keep the url address and map it onto the own domain?

I already have this, but this is only redirecting the homepage of blogspot to homepage of my own domain:

<script type='text/javascript'>
  var d='<data:blog.url/>';
  d=d.replace(/.*\/\/[^\/]*/, '');
  location.href = 'http://owndomain.com';
</script>

Upvotes: 2

Views: 366

Answers (1)

Rounin
Rounin

Reputation: 29463

Three simple steps.

1) Grab the current URI:

var blogSpotURI = window.location.href;

2) Then replace the blogspot domain with your own domain:

var ownDomainURI = blogSpotURI.replace('example.blogspot.com', 'owndomain.com');

3) Then point the browser at the new URI:

window.location.href = ownDomainURI;

Complete script:

var blogSpotURI = window.location.href;
var ownDomainURI = blogSpotURI.replace('example.blogspot.com', 'owndomain.com');
window.location.href = ownDomainURI;

Updated Version

/* grab URI from browser address bar */
var blogSpotURI = window.location.href; 

/* remove subdomain and domain */
var ownDomainURI = blogSpotURI.replace('http://example.blogspot.', ''); 

/* Find position of first forward slash after the TLD */
var slashPosition = ownDomainURI.indexOf('/');

/* Remove the TLD */
ownDomainURI = ownDomainURI.substring(slashPosition);

/* Add new domain and new TLD */
ownDomainURI = 'http://owndomain.com' + ownDomainURI; 

/* Point browser window at new address */
window.location.href = ownDomainURI; 

Upvotes: 2

Related Questions