2

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>
cplus
  • 1,115
  • 4
  • 22
  • 55

1 Answers1

2

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; 
Rounin
  • 27,134
  • 9
  • 83
  • 108
  • thanks. It is working but there is a caveat to it. As you know, the blogspot domain changes automatically to that country's domain name (if it exists), so it doesn't trigger the redirect, UNLESS, I change *example.blogspot.com* to *example.blogspot.de* for example, if the user is from Germany. How can we change the example.blogspot.com to something that can take any domain ending into account? – cplus Jan 28 '16 at 23:24
  • I've updated the post above (with explanatory comments) to take account that the blogspot address might include a TLD such as `.de`, `.es`, `.co.jp` etc. – Rounin Jan 29 '16 at 00:05
  • 1
    You are a hero, I wish I could give you more points to this help! Precious! – cplus Jan 29 '16 at 00:09
  • is it also possible to enable masking option to this script? while forwarding any url to the equivalen mydomain url, is it possible to show the original url in the url address bar? should I put this as a new question? – cplus Jan 30 '16 at 17:30
  • It's probably best to post this as a new question, yes. – Rounin Jan 30 '16 at 17:49
  • I created a new question here: http://stackoverflow.com/questions/35107593/mask-forwarded-blogger-urls-to-own-domain-urls – cplus Jan 30 '16 at 21:54