How to map subdomain to a domain with CNAME? - apache

I would like to point CNAME records for www.example.com to sub.example2.com. The hosting for example2.com is a shared hosting (cPanel without Addon domain feature).
So, what I did was to add a subdomain in the cPanel: sub.example2.com
I then added a CNAME record for www (and without www) of example.com to sub.example2.com
After propagation, www.example.com shows the default server page of the hosting instead of showing the sub domain contents. If I access this subdomain directly, it works fine.
Can somebody help me with these, please? Thanks.

If I understood your intent correctly, you have to tell cPanel that you want to serve www.example.com, not the other thing. Either that, or create a third virtual host somewhere (anywhere) that would handle www.example.com by doing a HTTP redirect to sub.example2.com.
Note also that you can't have a CNAME record for example.com without www, because a domain record already has SOA and NS records, and CNAME can't be combined with anything else - it has to be an A record.

Another thing to know about what you're doing:
You can't use a CNAME in the zone apex
(so as in the example.com zone a record "# IN CNAME example2.com")
Theoretically it is, but in reality too many (resolving) nameservers get confused.

Related

Latency with www prefix

Recently bought a new domain (cloud hosting account).Discovered that my site adds extra delay when invoked with "WWW" prefix in the browser.
However, the site does appear finally but its slower compare to invoking without "WWW"
why is this slow ? and can i improve this with any configuration ?
what is the best practice.
1]Once anyone register domain, domain name will be in naked form. Purpose is to link it to specific IP.Suppose example.com is domain name which is naked domain name linked to specific IP.Once domain is created, zone will be created too for it.
2]www.example.com shows sub domain of domain example.com and it has zone records automatically set which is of main domain example.com.So whenever someone browse www.example.com,it tries to identify zone records of example.com and then displays website.Hence there could be slight delay(mili seconds) while one would browse www.example.com compare to example.com
3]One should bind domain with www and without www

Cloudflare and cPanel issue - Reidrects back to main hostname

So I setup a subdomain off my regular domain. I then make an A record on Cloudflare to point to the IP address of my server. However, whenever I go to the subdomain, it just takes me back to the main hostname. (So i have sub.domain.com and when I go to sub.domain.com in my browser, it redirects me back to domain.com)
What could be the issue? I've checked .htaccess.
I've had similar issues with cPanel and Cloudflare before where cloudflare won't properly direct to the proper subdomain.
This is very difficult to look at without knowing the actual domain or subdomain in question. We don't do anything that would put a redirect in by default, so it sounds like it may be an issue on your server directly.

How do I access my local hosted website domain with both abc.com and www.abc.com?

I have my website hosted using XAMPP. I have a domain name purchased through 1and1, and have the A Record pointing at my ip address. The website works just fine if I type in abc.com, but if I try www.abc.com, I get a 404 error.
I called 1and1 up and they said they wont help because they are not hosting the site. They said to make it work I have to do htaccess rewrite.
I tried looking into this, but I cannot seem to find anyone having this issue.
Any help to figure this out would be amazing!
You will need to do two things:
1) Create one more DNS record for www.abc.com pointing to the same IP address.
2) In your virtual host configurations, look for ServerName abc.com. Add a server alias under server name.
ServerAlias www.abc.com

How to Redirect any subdomain request to main domain?

I'm trying to redirect all subdomain requests for domain.com to www.domain.com even when the subdomain does not exist, for example if we have:
abc.domain.com to www.domain.com
Where abc can be any requests. Furthermore, that subdomain abc may be exists or not. But whatever it is, I want to redirect it to main domain.
And less important request is. How it is possible to keep the input address at the address bar and redirect to main domain?
It will be best for me if it is done by .htaccess
I use apache server.
Thank you.
Since you haven't specified the environment you use, here are some general tips:
First, there is a difference between redirecting:
The user types sub.domain.com into the browser's address bar, but is redirected to domain.com -> domain.com is in the address bar, as the user is now on domain.com
...and rewriting an URL in the background:
The user types in sub.domain.com and stays at this address. The user sees sub.domain.com but in the background some other page (in your case, that one under domain.com) is loaded and shown.
(Quickly explained.)
If you are using Apache, take a look at 301 redirects and url rewriting.
In addition to what Piedone said (which is on the HTTP server side), you also need to configure the DNS to have a catch-all for all subdomains, directing them all to your HTTP server.
This implicitly means that all possible subdomains will exist automatically.

help regarding setting up pseudo/fake subdomains on apache

First of all, sorry if I got the term 'pseudo subdomain' wrong.
what I am trying to achieve is this-
When someone registers on my application, they get a new url like..
yourname.myapp.tld
I dont want to use the subdomain system for this. To be frank, I dont know how the subdomains exactly work but it guess it requires a folder per subdomain inside the document root and then the server redirects the requests there.
Can this be achieved by doing something like -
when a visiter types any subdomain, (anything.myapp.tld), he is able to access myapp . In the index.php file i will explode the $_SERVER['HTTP_HOST'] to get the subdomain which i will store in session and will thereafter act as an identifier for that user. Ideally i wouldnt want to create any vhosts or add many lines to the hosts file. Can this be achieved with just one vhost?
Is this possible with mod rewrite or something ?
Yes you can archive this using wildcard that needs to be configured on both, the dns server and http server
On the dns a entry like this (installing dns on ubuntu https://help.ubuntu.com/10.04/serverguide/C/dns.html):
; wildcard subdomains are all directed to this IP
; of course this should be the IP of your web server
*.domain.tld. IN A 1.2.3.4
At apache an entry like this:
<VirtualHost 111.22.33.55>
DocumentRoot /www/subdomain
ServerName www.domain.tld
ServerAlias *.domain.tld
</VirtualHost>
What happens after is that everything.domain.tld will be going to your main folder so you can use the index.php to redirect it to the right place or even an htaccess using mod_rewrite.