The cart is empty

Basic PHP Configuration Using .htaccess

Basic PHP Configuration Using .htaccess

Web applications sometimes require modifications to the PHP hosting settings. This is especially true for CMS systems like Joomla, Drupal, Wordpress, etc. Basic PHP settings can be adjusted using the .htaccess file, which can be placed in any directory or subdomain.

Below is an overview of parameters and their explanations:

Default Directory Indexes

  • Each index name is separated by a space, and correct capitalization should be observed.
DirectoryIndex index.php index.HTML default.php

When a domain is accessed, index.php is loaded from the server. If index.php is not present, index.html is loaded, and so on.

Directory Listing

  • To enable directory listing, simply add the following to your .htaccess:
Options +Indexes
  • To disable directory listing:
Options -Indexes

Custom Error Pages

  • You can specify the address as a URL or a relative path.
ErrorDocument 403 /error/error403.html
ErrorDocument 404 /error/error404.html
ErrorDocument 500 /error/error500.html

Magic Quotes

  • This setting affects the processing of data from forms, URLs, and cookies.
php_flag magic_quotes_gpc on

Displaying Script Errors

php_flag display_errors on

MultiViews

  • MultiViews operates based on file name extensions and the list of all variants for a given resource. For example, if a non-existent file image.JPG is requested, MultiViews will try to find the file as:
    • image.jpg
    • image.pdf
    • image.png

Blocking Access

  • To deny access to your site for certain users, you can use the following directives:
  • The first line specifies whether access will be allowed or denied.
Allow,Deny
  • At least one address must be allowed; otherwise, all accesses are denied.
Deny,Allow
  • At least one address must be denied; otherwise, all accesses are allowed.

Example:

Order Deny,Allow
Deny from all
Allow from 196.168.1.1

Access is allowed from IP address 196.168.1.1, while all other access attempts are denied.

Password Protection:

AuthUserFile /directory-with-passwords/.htpasswd
AuthType Basic
AuthName "Private Section"
require valid-user
  • AuthUserFile -> Specifies the directory containing the password file.
  • AuthType Basic -> Defines the authorization method.
  • AuthName -> Names the protected area.
  • require valid-user -> Tells the server to allow access only to authorized users.

The .htpasswd file contains usernames and passwords. The format is:

Login:encrypted-password

You can use tools like htpasswd generator to create encrypted passwords.