iGdux

耕读无限

Learner and Observer, be happy to share useful and nice things.
youtube
follow
tg_channel
github
email

About Xlog Custom Domain and Its Redirection Settings

The Xlog blogger gathers experts from various fields, including those familiar with Web3, blockchain technology, cryptocurrency wallets, and also includes novices in web technology who just want to share content.

As a novice in web technology, I encountered some issues with URL redirection while customizing the domain name for my Xlog blog. It seems there are no tutorials for naked domain redirection on Xlog. (After finishing this blog post, I found this tutorial, but it also did not include settings for naked domain redirection.) I followed the tutorial from ChatGPT and consulted with the expert Diygod, and ultimately resolved the issue. I am documenting this here in hopes of helping other Xlog users.

For convenience in writing, I will refer to the naked domain as igdux.com and the subdomain with www as www.igdux.com; readers should replace igdux.com and www.igdux.com with their own domain names when setting up.

This blog post actually provides two redirection solutions. The goal of the third section is to achieve: when we enter and access www.igdux.com, it will permanently redirect to igdux.com, and Google search engine will index igdux.com; the goal of the fourth section is to achieve: when we enter and access igdux.com, it will permanently redirect to www.igdux.com, and Google search engine will index www.igdux.com. Referring to Google's approach, I use and recommend the redirection solution presented in the fourth section.

The steps for customizing the domain name are as follows:

1. Configuration and Improvement of Xlog Subdomain#

Perhaps when you first register for Xlog, you might randomly write an Xlog subdomain; however, the subdomain can be modified, and it is recommended to change it to a short, memorable, or impressive subdomain. For example, I changed my Xlog subdomain to: https://igdu.xlog.app. The modification method is: enter the Xlog console, click on Settings — Domain — set it to your desired domain name, and save.

2. Setting Up a Custom Domain Name#

Xlog offers a free custom domain name solution. Here, I will take my Xlog blog https://igdux.com as an example. When I want to set the custom domain name https://igdux.com for https://igdu.xlog.app, the setting method is as follows: enter the Xlog console, click on Settings — Domain — Custom Domain, enter your domain name, such as igdux.com (do not enter https:// or http://), at this point, Xlog will ask you to verify the ownership of the domain.

As shown in the image:

xlogdomain (1)

Since my domain is hosted on the benevolent Cloudflare, when verifying domain ownership, I need to set the domain verification values in the Cloudflare account that hosts the igdux.com domain: including a CNAME value and a TXT value. Just fill them out as required.

As shown in the image:

xlogdomain (3)

If set up correctly, after a moment, you can access your blog through the custom domain name (you can also access it through the originally assigned xlog.app subdomain).

3. Setting Up 301 Naked Domain Redirection, Target Effect is www.igdux.com Redirecting to igdux.com (Optional Solution)#

Naked domain redirection means that when accessing the www.igdux.com domain, it will redirect to the non-www domain igdux.com. A 301 redirect means setting a permanent redirect, not temporary, which is convenient for search engines to recognize and mark.

Usually, blog platforms have options for domain redirection in the backend, such as Google Blogger (note: Blogger defaults to redirecting from the non-www domain to the www domain). However, Xlog's backend does not have a domain redirection option. At this point, you need to set up domain redirection with your domain registrar, such as Cloudflare.

3.1 Setting Up www Domain Resolution#

There are two methods for setting up www domain resolution, only one can be chosen. Diygod chose method one, and I successfully tested method two.

Method one: Add an IP resolution for the domain with www. The A record value can be any standard IP value (not necessarily Cloudflare's IP), such as 192.0.2.1 or 108.162.192.233. After setting it up, as shown in the image:

xlogdomain4

Method two: Add a CNAME resolution for the domain with www, where the resolution value can be your Xlog.app subdomain. For example:

xlogdomain (2)

3.2 Setting Up 301 Redirect Rules#

Method one: Set up a 301 redirect through Page Rule
In your Cloudflare account, select the custom domain name bound to your xlog.app subdomain, for example, my custom domain name is igdux.com. Select the domain — Rules — Page Rules, set it as shown in the image:

xlogdomain 4

URL: your domain/* (e.g., google.com/*)

Pick a Setting: Forward URL; Select Status Code: 301

Enter Destination URL: https://your domain/$1

Where /* and /$1 are common web technology language, just set it as shown in the image.

After you complete steps 3.1 and 3.2, you can access your blog through your domain, and you can also achieve naked domain redirection: for example, when I access https://www.igdux.com, it will automatically redirect to https://igdux.com. If you set the 3.2 domain 301 redirect rule but did not set the 3.1 www domain resolution, you will encounter an HTTP 502 error.
Method two: Set up a 301 redirect through Redirect Rule
Since Cloudflare is about to discontinue support for Page Rule, consider using Redirect Rule to set up 301 redirects in advance.
In your Cloudflare account, select the custom domain name bound to your xlog.app subdomain. Select the domain — Rules — Redirect Rules — Create Rule.
When creating the Redirect Rule, customize the rule name to something memorable, such as www2Rootdomain, etc.

redirect

Fill in the redirect rule as shown in the image. Note that when setting your own "If" condition, you need to change the www.igdux.com in the image to your own domain that needs to be redirected. In the "Then" condition, select type (Type) as dynamic (Dynamic), and expression (Expression) as concat("https://igdux.com", http.request.uri.path), you need to modify https://igdux.com to your target redirect domain, and select the redirect status code (Status Code) as 301 to achieve a permanent redirect. After setting the redirect rule, remember that the domain needs to be added to Cloudflare CDN. This way, you can achieve a permanent (301) redirect from the redirected domain to the target domain. (For method two, refer to Source 1 for content, special thanks.)

Custom Domain Name Successfully Set#

If your Xlog custom domain is www.igdux.com, during verification, follow the prompts to set it up. In addition to a TXT verification for the domain, there will also be a verification for the CNAME resolution value for the domain www.igdux.com, which is your xlog subdomain (my xlog subdomain is igdu.xlog.app).

image

Once the domain verification (authentication) is successful, you can access the blog by entering https://www.igdux.com, but at this point, you cannot access the blog via https://igdux.com. Therefore, it is necessary to set up a 301 redirect from https://igdux.com to https://www.igdux.com.

The steps for setting up are similar to those in section 3 above, just with some data adjustments. Key steps are recorded as follows:

Resolve the Naked Domain igdux.com#

There are two methods:
Method one, perform an A record resolution for igdux.com, with any IP value, as shown in the image:

image

Method two, perform a CNAME resolution for igdux.com (replace with your own naked domain), with the value being cname.xlog.app; everyone can set it up successfully; image omitted.

Set Up 301 Redirect from Naked Domain igdux.com to the www Subdomain#

As shown in the image:

image

Thus, we can redirect from the naked domain igdux.com to the subdomain www.igdux.com, and the main address of the blog is also the domain with www, www.igdux.com.

Note:#

Although Google Blogger's backend includes domain redirection, Blogger defaults to redirecting from the non-www domain to the www domain; if Blogger users want to set up naked domain redirection, they should not set the option to redirect from the non-www domain to the www domain in the Blogger backend. At the same time, refer to the settings in this article to achieve naked domain 301 redirection.

Acknowledgments:#

Thanks to Diygod and ChatGPT. After encountering issues, with the help of ChatGPT and guidance from the expert Diygod, I successfully resolved the domain redirection problem.

————

Please Follow:#

This article is simultaneously published on iGengdu Blog and Linux.do Forum.

Regarding Xlog, please pay attention to the previous articles I wrote:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.