.htaccess in DirectAdmin hosting
Use .htaccess on DirectAdmin hosting for redirects, password protection, PHP settings, and custom error pages. Includes ready-to-use examples for common tasks.
On this page
.htaccess is a configuration file that controls how Apache handles requests in the directory it is placed in. DirectAdmin hosting uses Apache, so .htaccess is fully supported. Changes take effect immediately-no restart needed.
What is .htaccess?
The .htaccess file sits in your public_html/ directory (or any subdirectory). Rules placed in it affect that folder and all subfolders unless overridden. Common uses:
- URL redirects (301 permanent, 302 temporary)
- Force HTTPS for all traffic
- Override PHP settings (memory limit, upload size)
- Password-protect a directory
- Block specific IPs or user agents
- Custom 404 and 500 error pages
WordPress uses .htaccess for its permalink routing. Do not delete the WordPress-generated section.
Edit .htaccess in DirectAdmin
- Log in to DirectAdmin and open File Manager
- Navigate to
domains/yourdomain.com/public_html/ - The
.htaccessfile starts with a dot-enable "Show Hidden Files" if it is not visible - Click the file to edit it, make your changes, and click Save
Apache will return a 500 Internal Server Error for the entire directory if .htaccess contains a syntax error. Download a backup copy before editing. If you break the site, re-upload the original file to restore it.
Redirects
301 permanent redirect (old URL to new URL):
Redirect 301 /old-page https://yourdomain.com/new-page
Redirect non-www to www:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
PHP settings via .htaccess
These directives work when PHP runs as an Apache module or suPHP. They may be ignored on FastCGI/PHP-FPM setups:
php_value memory_limit 256M
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 120
Password protect a directory
Create a .htpasswd file first (use an online bcrypt generator or ask support). Then add to .htaccess:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/username/domains/yourdomain.com/.htpasswd
Require valid-user
Replace the path with the full server path to your .htpasswd file.
Custom error pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
Create the HTML files at those paths in public_html/. This gives visitors a branded error page instead of the server default.
Related: DirectAdmin File Manager | DirectAdmin security | .htaccess guide | 403 Forbidden error
Need DirectAdmin hosting?
DirectAdmin is available for customers who want a lightweight hosting control panel on compatible UnderHost services.





















