Allright, on the previous post I had made a tutorial how to use your own custom domain on xtgem and also mentioned that your original xtgem subdomain are not have 301 redirect to your parked domain.


xtgem guides and tutorials by weblogwap

Now on this post, we will try to workaround the parked domain redirection on xtgem so that visitors who visit your xtgen site will be redirected to your new parked domain.

Well, it would be nice if xtgem has PHP support. Not necessary as a free feature, but I will sure paid it even if it require a premium subscription hehe. But no, the most possible way to do this is by using Javascript either meta refresh.

Well, this is the script I compose and use on my xtgem site to redirect my xtgem site subdomain address to the parked domain. You can try access it here: gratrik.xtgem.com. You will be automatically redirected to the parked domain on www.gratrik.gq. You can open one of the page there, and try to edit the link and replace "www.gratrik.gq" with "gratrik.xtgem.com" then visit it to see the script in action once more redirect you to the same url path, but with "www.gratrik.gq" domain.

Parked domain redirection script for Xtgem sites

This script uses two method, it is using Javascript and meta refresh. The two method have its own advantage and disadvantage:

- Javascript
Advantage: Redirect instantly as soon as the script being read by browser
Disadvantage: If visitor disabled the Javascript or are using an old unsupported browser, you are done.

- Meta refresh
Advantage: A basic command that every browser guaranteed to understand.
Disadvantage: At the very least, visitor must wait until the page is fully loaded before the redirection happening so it's possible they will be annoyed by sudden browser refresh .

So in this script I combined Javascript and meta refresh. Javascript goes first and do the job to redirect your visitor to your parked domain address on your xtgem site instantly even when the screen still blank using window.location.replace() function.

If Javascript fails (e.g. user disabled Javascript), then meta refresh will do the job on your xtgem site. Keep in mind that even if we set the refresh interval to 0, the browser must finish loading your xtgem site first before the redirection happening (Tested on Windows tablet using Firefox 59). Here is the codes:


<script>
var newDomain = 'MY_PARKED_DOMAIN';
var thisURI = window.location.href;
if (window.location.hostname != newDomain) {
var newURI = thisURI.replace(window.location.hostname, newDomain);
window.location.replace(newURI);
}
</script>

<!--parser:xtscript-->
var $customDomain = MY_PARKED_DOMAIN
var $sColon = call chr $val=59
var $currentDomain = <xt:url type="domain"/>
var $thisURI = <xt:url />
var $thisDomain = call substr $val=$thisURI; $start=7; $length=99
var $path = call stristr $haystack=$thisDomain; $needle=/; $before_needle=0;
var $thisDomain = call stristr $haystack=$thisDomain; $needle=/; $before_needle=1;
if $currentDomain != $customDomain
print <meta HTTP-EQUIV="refresh" CONTENT="0;URL='http://$customDomain$path'" />
endif;
<!--/parser:xtscript-->

Replace MY_PARKED_DOMAIN (on line 2 and 11) with your parked domain on your xtgem site (e.g.: www.mydomain.com).

Include the codes to the most top line in your _headtags file on your xtgem site and save it.


How to create a subdomain on your xtgem site

Next xtgem domain tutorial is how to make a subdomain under your xtgem site. I got this tutorial from syntax.xtgem.com site.

This is also can be applied even if you are still using xtgem subdomain on your site. Though it's not recommended if you still haven't used a top level domain on your xtgem site as it will make it more inconvenience (e.g.: subdomain.mysite.xtgem.com).

The basic concept here is, make a subdirectory on your xtgem site root, and the subdirectory index file will become the subdomain of our xtgem site.

Live demo of the subdomain trick on xtgem on my xtgem site:
- unduhapp.wapgem.com/news/index, by access it you will see the news page on my xtgem site.
- news.unduhapp.wapgem.com, but the index page inside news subdirectory can also be accessed by this url.

Quoted from syntax.xtgem.com:

Subdomains are easy to set up but tricky to get working smoothly.
Basically any folder HTML page or even a media file page (no . file extensions allowed) can be a subdomain of your site all you need to do is create the folder and create a index file in it or just create the HTML page.
The folder's index page the file or HTML page can then be accessed as http://sub.site.xtgem.com

If we include the <base> tag code in our _headtags file, we can make some adjustments especially the url write rule.


<base href="http://YOUR SITE.COM" />
Replace "YOUR SITE" with your main domain.

These rules apply should we include or not the code above in our xtgem site _headtags file:

WITH <base> tagWITHOUT <base> tag
Relative addresses are relative to the main site NOT the subdomainRelative addresses are relative to the subdomain NOT the main site
Links to other pages or files in the subdomain MUST use full http addresses including the subdomain ie: http://subdomain.site.xtgem.com/folder/fileLinks to pages or files in the main site MUST be full http addresses ie: http://site.xtgem.com/folder/file
-_header _footer _headtags files will not work for the subdomain if they contain relative addresses
-Most of the addresses created by the building tool for links or images using the filebrowser will be incorrect when the page is viewed as a subdomain