How do I create 'www' domain alias automatically? - dns

I created CNAME record for new domain: www CNAME #, now, if I have many domains, shoud I always create a link 'www.example.com' to 'example.com' folder? My apache VHOST config is:
UseCanonicalName Off
VirtualDocumentRoot /home/colix/www/hosts/%0
VirtualScriptAlias /home/colix/www/hosts/%0/cgi-bin

for this case I always use ServerAlias directive in the config (see Apache Doc).
ServerName domain.tld
ServerAlias www.domain.tld
ServerAlias mx.domain.tld
Greetings,
M.

Related

VPS: xy.com working, but www.xy.com not

I set up a VPS for my project, but I can access it with myawesomeproject.com, but I got DNS error with www.myawesomeproject.com
My apache conf:
<VirtualHost *:80>
DocumentRoot /var/www/myawesomeproject/public
ServerName myawesomeproject.com
ServerAlias www.myawesomeproject.com
<Directory "/var/www/myawesomeproject/public/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/myawesomeproject-error_log
</VirtualHost>
I only have one DNS zone for it at the registrar:
Type - IP - TLS
A - 'MyVPS'sIP' - 3600
What's the problem?
The A Record is probably for your naked domain, so that's why the version without WWW is working.
You need to make an A record for the www subdomain pointing to the same IP as the naked domain, or create a CNAME record pointing to the naked domain.
Cheers

How to access to site by 2 address

I have a site now with address https://example.com/. How to make possible access to this site also by address https://example.com.html? What to write in htaccess?
What to write in htaccess?
Nothing special.
The question is not what to write but what to not write in .htaccess. And the answer is: do not write anything that links the site to one of its names (example.com or example.com.html). The same applies to the PHP source or configuration files.
The rest is just proper names registration, nameserver and Apache configuration.
Regarding the configuration of Apache, let's say the IP address of your web server is 1.2.3.4. The Apache configuration file (httpd.conf f.e.) now contains something similar to this:
<VirtualHost 1.2.3.4:80>
ServerName example.com
DocumentRoot "/www/docs/example.com"
# Other configuration directives for domain example.com
</VirtualHost>
In order to let Apache know the domain example.com.html is the same as example.com you can add a ServerAlias to the <VirtualHost> block:
<VirtualHost 1.2.3.4:80>
ServerName example.com
ServerAlias example.com.html
DocumentRoot "/www/docs/example.com"
# Other configuration directives for domain example.com
</VirtualHost>
Assuming you already have the name and the name servers are properly configured to point to your existing server, restart Apache and it should work.
Read more about <VirtualHost> and ServerAlias

Why is my virtualhost defaulting to the standard document root?

I have two domains registered: example.com and example.org. For one of these, I have also registered a subdomain: sub.example.com.
I successfully managed to set up a virtual host for my subdomain sub.example.com. So example.com points to the default document root /var/www and sub.example.com points to /var/www/sub.example.com.
But for some reason, I can't get example.org to point to anything else than the default document root. So example.com and example.org leads to the same website. I have created a virtual host for example.org, but Apache doesn't seem to register it.
# /etc/apache2/sites-available/example.org
<VirtualHost *:80>
ServerAdmin admin#example.org
ServerName example.org
DocumentRoot /var/www/example.org
</VirtualHost>
Have you enabled the website?
With a2ensite example.org you can enable your site. Then do service apache2 reload to reload the websites.

virtual hosts are linked to internal address

I am trying to transfere my website in my new server.
I have an internal adresse.ex: xxx-wwwyyy.net
www.site1.com : production web site
www.site2.com : preproduction web site
In my site-available folder I created some vhost files:www.site1.com and www.site2.com
The problem is that both of them are linked to xxx-wwwyyy.net:
If I create a vhost for xxx-wwwyyy.net and i give it my site folder adress:
/var/www/site/prod ,
then my **www.site1.com** and **www.site2.com** go to the same adresse.
If I delete xxx-wwwyyy.net , all of them go to /var/www/
I am just confuised. has anyone any idea?
hello you are trying to create name-based virtual hosts.. make sure NameVirtualHOst *:80 is uncommented in your httpd.conf ... have a look in here:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Domain that shows another domains subdirectory

Is it possible to have e.g. "domain.com" that shows "domain2.com/dir".
What I mean is, that instead of domain.com just redirecting, I want it to show e.g. "domain2.com/dir/subdir" as "domain.com/subdir"
All this is regarding to a CMS.
What I need is, that my frontend to my CMS is at domain.com. A customer is creating his account with a shorttag. E.g. "domain2.com". Then their unique URL to THEIR frontend is "http://domain.com/domain2.com".
What I need is, that domain2.com can show "http://domain.com/domain2.com" - so that the customers doesn't need to redirect their users to http://domain.com/domain2.com, but can simply just redirect to their own domain - domain2.com
Thanks in advance.
If you're using cPanel you can set up an addon domain that can point to a specific directory.
If you're just using apache you'll need to point the domain to another folder in the vhosts.
<VirtualHost *:80>
DocumentRoot "/home/user/domain.com"
ServerName domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/home/user/domain.com/dir"
ServerName domain2.com
</VirtualHost>
you can use http header in your first page(domain2.com/dir/subdir) to redirect to second page
in php this is something like this (in index.php file in subdir):
<?php
session_start();
header('Location: http://domain.com/dir');
die();
?>

Resources