apache2 - can I setup a subdomain without creating an A record? - apache

So I have
mydomain.com
and I want
test.mydomain.com
Can I set this up without creating an A record for the subdomain? Either with .htaccess or

You need something in DNS. It can be an A, a CNAME, or you can use a wildcard entry like
*.mydomain.com. IN CNAME mydomain.com.
The above is a wildcard record, which will match any name under mydomain.com. You can also use a record for your specific name.
; an alias name pointing to mydomain.com
test.mydomain.com. IN CNAME mydomain.com.
; or, a regular DNS record
test.mydomain.com. IN A 1.2.3.4
Without a DNS entry, the browser will not know about your Apache instance to begin with. So you cannot solve this with .htaccess or Apache config alone, DNS must route the request to Apache first.

Related

How to redirect www to root (#)?

How do I setup an alias so that www.mydomain.com permanently redirects to mydomain.com using Zeit now CLI?
I tried now dns add mydomain.com www CNAME mydomain.com but it does not work.
It seems * CNAME alias.zeit.co is prioritized over www CNAME.
First, you need to add an alias pointing your deployment to your root domain.
now alias my-deployment-url.now.sh example.com
Then you need to add a redirect. Since this is not possible with DNS, you need to have some web server emit a 301/302 redirect. In this case, we'll make a new deployment.
now -e REDIRECT_URL=https://example.com now-examples/redirect
Now that we have this new "redirect" deployment, we'll alias it as www like so:
now alias https://redirect-otytioldup.now.sh www.example.com
See the docs for more info.

How to map subdomain to a domain with CNAME?

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.

CNAME in Heroku - what to use for alias?

I am trying to use a custom domain in Heroku, but the instructions are not working for me.
Heroku instructions are at https://devcenter.heroku.com/articles/custom-domains
I changed CNAME at my host to several things, because the instructions in Heroku are really unclear.
For CNAME alias, I tried several things:
www.example.com
example.com
www
proxy.heroku.com
And for my address, they all point to the same thing: www.morning-harbor.herokuapp.com
I use moniker.com's DNS servers. However, when I try on the command line
host www.example.com
It points me to my old virtual server IP address, not Heroku or moniker.com
Which one is the right CNAME alias to use?
make a CNAME FROM www TO morning-harbor.herokuapp.com
you cant have a CNAME for apex records (yourdomain.com)

Sub domains on the fly or Wild Card subdomains

Is it possible to redirect everything in a subdomain to the main domain.
Eg
anything.example.com
something.anything.example.com
must all go to example.com
and
anything.example.com/page.php
something.anything.example.com/page.php
must all go to example.com/page.php
is this possible ? on a shared host ?
yah, sure that's possible. just set up a subdomain that's a wildcard (* on most apaches) and set the VH to be the site root.
It's possible if you have access to the DNS records.
You have to add an A-record, with as values * and the ip of example.com

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.