I would like to describe it specifically like this:

I have a domain example.com managed with Cloudflare and a website managed with CyberPanel.

I created a domain alias sub.example.com in CyberPanel and created a DNS record type A, name = sub, content = IP of the host. When I access sub.example.com/path, it displays the same content as the original domain and the URL displayed is the subdomain, but if I click on the home page or another article, it automatically redirects to the original domain.

For example:

Current link: sub.example.com/path1

When I click on another page whose path is path2, it redirects to example.com/path2, not sub.example.com/path2. I wonder if I need to set anything in the .htaccess file to keep the subdomain active on all pages of the website.

1

There are 1 answers

0
Mr.Manoj M Gowda On

To resolve this, you can follow these steps:

Check Your DNS Configuration:

Ensure that the DNS record for your subdomain sub.example.com is correctly configured in Cloudflare. As you mentioned, you've already created a DNS record type A, but double-check that it points to the correct IP address.

Check CyberPanel Configuration:

Make sure that the subdomain sub.example.com is properly set up in your CyberPanel. Ensure that it's associated with the correct website directory and doesn't have any redirects configured within CyberPanel itself.

.htaccess File Configuration:

To keep the subdomain active on all pages, you can add or modify rules in your website's .htaccess file. Here's a sample rule you can add to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com [NC]
RewriteRule ^(.*)$ http://sub.example.com/$1 [L,R=301]

This rule checks if the incoming request is for "sub.example.com" and if so, it rewrites the URL to use the subdomain throughout. This should prevent automatic redirects to the original domain.

Clear Browser Cache:

After making changes to your configuration, clear your browser's cache and cookies. Sometimes, browsers can cache redirects, and clearing your cache ensures that you're testing with the most recent settings.

Cloudflare Configuration:

In some cases, Cloudflare settings can affect redirects. Double-check your Cloudflare settings to ensure that there are no page rules or firewall rules causing unwanted redirects.

Check for CMS/Website-Specific Settings:

If your website is running a CMS (Content Management System) like WordPress or Joomla, check for any settings within the CMS itself that might be causing redirects.

After making these changes, test your subdomain "sub.example.com" by clicking on various pages. It should now keep the subdomain active for all pages and not redirect to the original domain. If the issue persists, you may want to consult your hosting provider's support or CyberPanel's documentation for additional assistance.