Managing .htaccess Files

7 vues Website Management

Understanding .htaccess

The .htaccess file is a powerful configuration file used by the Apache web server. It allows you to control URL redirects, password protection, caching, and many other features on a per-directory basis without modifying the main server configuration.

Locating and Editing .htaccess

  1. Open DirectAdmin File Manager.
  2. Navigate to your public_html directory.
  3. If you do not see a .htaccess file, ensure hidden files are visible (look for a Show Hidden Files option).
  4. Click on .htaccess to edit it, or create a new file named .htaccess if one does not exist.
Always back up your existing .htaccess file before making changes. A syntax error in this file will cause a 500 Internal Server Error for your entire website.

Common .htaccess Rules

Redirect HTTP to HTTPS:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect www to non-www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]

Password-Protect a Directory:

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/username/.htpasswds/public_html/passwd
Require valid-user

Block an IP Address:

Deny from 192.168.1.100

Set Custom PHP Values:

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300

URL Rewriting

The mod_rewrite module enables clean, SEO-friendly URLs:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Most CMS platforms like WordPress automatically create and manage their own .htaccess rules. If you are adding custom rules, place them above or below the CMS-generated block and do not modify the auto-generated sections.
Besoin d'aide ?

Vous ne trouvez pas ce que vous cherchez ? Notre équipe de support est prête à vous aider.

Contacter le support
Bonjour ! Comment pouvons-nous vous aider ?
Discuter