Posts Tagged ‘apache2’

Apache2 unseting AddDefaultCharset (via .htaccess)

Tuesday, July 27th, 2010

Setting a default charset using .htaccess is a simple thing to do

However sometimes there is a need to unset default charset as well (for instance if the AddDefaultCharset is set in the apache config and this is causing problems).

This is very easy to do just edit the .htaccess file and add a line that says

AddDefaultCharset OFF

.htaccess – limit access by ip (or range of ips)

Friday, March 19th, 2010

Using a .htaccess file it is not hard to limit access to a directory to only certain ips.

order deny,allow
deny from all
allow from 10.8.0
allow from 81.257.140.212

Using only a partial ip (like 10.8.0) means a wildcard so all of the 10.8.0.0/24 rage is allowed.

apache2 could not reliably determine the server’s fully qualified domain name using 127.0.0.1

Monday, January 25th, 2010

When apache complains like this.

  • check that the virtualhosts so that ServerName is set to a FQDN
  • check /etc/hostname [should be a fqdn] (after you have updated this, run “/bin/hostname -F /etc/hostname”
  • check /etc/hosts
  • Hint: use “apache2ctl configtest” to see if it helps

Apache2 changing charset using .htaccess

Thursday, January 14th, 2010

If you do not wish to change character encoding for the entire server, but only one site (or only one directory) then this is possible to do using .htaccess.

AddDefaultCharset UTF-8

If you only wish to do this to php or htm files (and not all files)

<FilesMatch "\.(htm|php)$">
AddDefaultCharset UTF-8
</FilesMatch>

If you wish to modify the mime-type as well as the encoding (on html files in this example)

AddType 'text/html; charset=UTF-8' html

Apache2 virtualhosts

Monday, January 4th, 2010

In order to bind a virtualhost to only one ip (if the server has several) add the ip in the VirtualHost tag, to make it listen on all ips – use *
To make the server respond to several names, use the ServerAlias and ServerAlias supports wildcards.

See the examples below for more.

<VirtualHost 111.22.33.55>
    DocumentRoot /www/subdomain
    ServerName www.sub.domain.tld
    ServerAlias *.sub.domain.tld
    ...
</VirtualHost>
<VirtualHost *>
    DocumentRoot /www/domain
    ServerName www.domain.tld
    ...
</VirtualHost>