1. Websta Hosting
PHP & Server Configuration

Using .htaccess for Redirects and Rules

Using .htaccess for Redirects and Rules

The .htaccess file (in public_html/) controls Apache's request handling for your site.

Enable "Show Hidden Files" in the DirectAdmin File Manager to see it.

Force 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%{REQUEST_URI} [L,R=301]

Redirect a Specific Page

Redirect 301 /old-page https://yourdomain.com/new-page

Block Access to Sensitive Files

<FilesMatch "\.(env|log|sql|bak)$">
    Order allow,deny
    Deny from all
</FilesMatch>

Set Custom Error Pages

ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

Increase PHP Upload Limits (mod_php only)

php_value upload_max_filesize 64M
php_value post_max_size 64M

For PHP-FPM (most modern servers), use .user.ini instead.

Still need help?

If this article didn't answer your question, our support team can help.

Contact support
All articles More in PHP & Server Configuration