.htaccess files

From Servage Wiki
Jump to: navigation, search

Contents

How do I enable .htaccess files?

In order to use .htaccess files with your Servage Hosting account the feature has to be enabled in the control panel. Otherwise our webserver will ignore it.

You find the function "Set .htaccess Files" in the control panel at "Webserver > Set .htaccess files".


How do I make simple error messages with .htaccess files?

Copy these lines below into a .htaccess file: (It will show only whats between the "" then the error comes).

# 400 Bad request:
ErrorDocument 400 "Bad request."

# 401 Authorization Required:
ErrorDocument 401 "Authentication required."

# 403 Forbidden:
ErrorDocument 403 "Forbidden access."

# 404 Not Found:
ErrorDocument 404 "Page not found."

# 500 Internal Server Error:
ErrorDocument 500 "Server error."

# 503 Service unavailable:
ErrorDocument 503 "Service unavailable."

You can also use HTML in them:

# 404 Not Found:
ErrorDocument 404 "<center>Page not found.</center>"

If you need to link to own pages:

ErrorDocument 500 http://caucasusnews.com/news
ErrorDocument 404 http://caucasusnews.com/news
ErrorDocument 401 http://caucasusnews.com/news
ErrorDocument 401 http://caucasusnews.com/news
ErrorDocument 403 http://caucasusnews.com/news
ErrorDocument 404 http://caucasusnews.com/news


How do I deny one/multiple IP-adresses/hostnames/domains with .htaccess files?

Copy these lines below into a .htaccess file:

AuthName "Access for webmaster only."
AuthType Basic
<Limit GET POST>
order deny,allow
deny from all
allow from 11.222.123.99
</Limit>

Change "11.222.123.99" with your own IP-adress (use only if you have static IP).

With more IP-adresses/hostnames/domains:

# Block a subnet, e.g. 123.234.56.0 through 123.234.56.255
deny from 123.234.56.

# Block a specific host name
deny from machine.domain.com

# Block a given domain name:
deny from .otherdomain.com


PHP-flags to turn things on and off

Copy these lines below into a .htaccess file:
Remove this character: # (for enabling/put it back for disabling).
Note: Multiple choices below.

# php_value safe_mode 0
# php_flag safe_mode 0
# php_value safe_mode off
# php_flag safe_mode off

# php_value safe_mode_gid 0
# php_flag safe_mode_gid 0
# php_value safe_mode_gid off
# php_flag safe_mode_gid off

# php_value register_globals 0
# php_flag register_globals 0
# php_value register_globals off
# php_flag register_globals off


Alternative Index Files

You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to 'index' files though. Using .htaccess you can set foofoo.blah to be your index file if you want to!

Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exisit it will display a directory listing (unless, of course, you have turned this off).

DirectoryIndex index.php index.php3 index.html index.htm


Save bandwidth with .htaccess

If you pay for your bandwidth, this wee line could save you hard cash.

<ifModule mod_php4.c>
php_value zlib.output_compression 16386
</ifModule>

All it does is enables PHP's built-in transparent zlib compression. This will half your bandwidth usage in one stroke, more than that, in fact. Of course it only works with data being output by the PHP module, but if you design your pages with this in mind, you can use php echo statements, or better yet, php "includes" for your plain html output and just compress everything!

Remember, if you run phpsuexec, you'll need to put php directives in a local php.ini file, not .htaccess.


Set $_SERVER['HTTPS'] for SSL Connections

As we are using a dedicated Proxy server to serve all Encrypted, secure https connection the HTTPS Flag does not get set automatically inside of PHP. We are using a different Header flag named HTTP_SSL to indicate if the request is being delivered via https to the enduser. Usually we recommend just to enable the automatic redirection for all http to https requests but in cases this would not do you can use the following .htaccess code to set the traditional HTTPS var inside of PHP:

#set HTTPS env in condition of Servage HTTPS Flag
SetEnvIf SSL "on" HTTPS=1
Personal tools
Navigation