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
Related
I currently have example.com pointing to Server one. I wanted to server example.com from a different directory ( /WebData )
I did this by editing httpd.conf
http://pastebin.com/UjHhRNTX
I this works as desired.
I then found out I needed to add website.org to the server. So I mounted another disk and created a dir called /WebDataWebsite
and created /etc/httpd/conf.d/websiteorg.conf with the following VHost:
http://pastebin.com/GTmqtABf
<VirtualHost *:80>
DocumentRoot "/WebDataWebsite"
ServerName website.org
ServerAlias www.website.org
<Directory "/WebDataWebsite">
Require all granted
</Directory>
</VirtualHost>
For some reason all traffic to example.com and website.org were both directed to index.htm in /WebDataWebsite
What I am doing wrong? How to I make /WebData (in httpd.conf) the default website but filter by servername website.org with the VHost?
You'll probably need to use Alias's for the second site. Have a look at http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias
It's unlikely that second declaration of the VH is being picked up by apache as it can not deal with two declarations of the same I believe.
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.
Okay so... i tried using
ServerName something.ooo
ServerAlias www.something.ooo
but it appears..
you can not use ServerAlias unless it is used within a
<VirtualHost *:80>
</VirtualHost>
Why is it like that?
What happens if the server is used only with 1 domain name and thus there is no need for "VIRTUAL" things. such as "VIRTUALHOSTS" ?
VirtualHost is designed to be used with multiple sites, however, when using an alias, Apache is assuming that you have example.com, and are wanting widget.example.com. With that said, just because it's only a www, does not mean that Apache doesn't see those as "separated" domains, thus needing a VirtualHost tag.
This is why you can use ServerName, but can't use ServerAlias without VirtualHost. WWW and non-www are separated domains.
I have recently just set up a RHEL based server running two domains. However, I am having difficulty hitting both domains from the browser. My config is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domainA.com
ServerAlias domainA.com *.domainA.com
DocumentRoot /home/domainA/public_html
<Directory "/home/domainA/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domainB.com
ServerAlias domainB.com *.domainB.com
DocumentRoot /home/domainB/public_html
<Directory "/home/domainB/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
The problem is when I navigate to domainA.com I hit the correct Virtualhost (which is fine), however when I navigate to domainB.com it displays the Apache Test page.
Edit
I have a Firewall between the webserver and the web. I tested the rules governing Domain A and Domain B.
Domain A reaches target and a status 200 is returned.
Domain B reaches target and a status 403 (permission denied) is returned
What you need to do is take a look at sites-enabled and sites-available.
Here's the first entry when Googling: http://www.debian-administration.org/articles/412
Looks reasonable and should help you integrate that.
The problem is that you need separate entries for all the sites you want to run on this apache2. Simple entries in your config file don't do it. Only the first works, the rest is more or less ignored. Creating separate entries with sites-enabled and sites-available is the way to go here.
I have done this in IIS7.5 with ease.
Say I have a domain mbdev.myftp.biz.
On IIS I have setup sites but each one has a different port.
Example:
mbdev.myftp.biz:8004
mbdev.myftp.biz:8006
The only thing that is different is the port for the site. Those above URL's got to actual sites on the IIS box.
How can I accomplish the same thing with APACHE? Having the site be on a specific port?
For Example:
mbdev.myftp.biz:8600
mbdev.myftp.biz:8601
Apache accomplishes this through the VirtualHost directive. Documentation for version 2.4 can be found on http://httpd.apache.org/docs/2.4/vhosts/index.html and more specifically the configuration directive http://httpd.apache.org/docs/2.4/mod/core.html#virtualhost
An example virtualhost config directive pulled from the link above:
<VirtualHost 10.1.2.3:80>
ServerAdmin webmaster#host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log
</VirtualHost>