Forward blogger urls to own domain urls
Asked Answered
S

1

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>
Stjohn answered 28/1, 2016 at 21:31 Comment(0)
S
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; 
Skylar answered 28/1, 2016 at 21:51 Comment(6)
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?Stjohn
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.Skylar
You are a hero, I wish I could give you more points to this help! Precious!Stjohn
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?Stjohn
It's probably best to post this as a new question, yes.Skylar
I created a new question here: #35108093Stjohn

© 2022 - 2024 — McMap. All rights reserved.