Quick summary
- What it is: The .htaccess (from HyperText Access) is a configuration file used by the Apache web server to apply directives to a directory and all its subdirectories.
- What it's for: it helps create, maintain or automate websites and applications hosted on the server.
- When to check it: when developing a website, modifying code, automating tasks or configuring an application.
The .htaccess (from HyperText Access) is a configuration file used by the Apache web server to apply directives to a directory and all its subdirectories. It is placed directly in the folder you want to configure — usually in the site root, inside public_html — and affects server behavior for that directory.
What is the .htaccess used for?
It is one of the most useful and powerful files in shared hosting. Among its most common uses:
- Redirects: Redirect old URLs to new ones, from HTTP to HTTPS, or from www to non-www.
- Force HTTPS: Force all traffic to use a secure SSL connection.
- Custom error pages: Display a custom page for 404, 500 errors, etc.
- Directory protection: Require a password to access a folder.
- IP blocking: Deny access from specific IPs.
- URL rewriting: Create SEO-friendly URLs (using mod_rewrite). WordPress uses it for its permalinks.
- Cache control: Tell the browser how long to cache certain file types.
Where is the .htaccess file?
It is in the root of your website, inside public_html/. Since its name starts with a dot, in some operating systems and file managers it is hidden by default. You can view and edit it from the file manager in DirectAdmin or cPanel, or by connecting via FTP and enabling the display of hidden files.
Usage example: forcing HTTPS
One of the most common rules in .htaccess is this one, which redirects all HTTP traffic to HTTPS:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
When will you encounter it?
The .htaccess frequently appears when:
- You have a 500 error and suspect there is an incorrect directive in the file.
- You install WordPress and want to configure the permalinks.
- You want to force the site to load over HTTPS after installing an SSL certificate.
- You receive support instructions to add or modify a specific rule.
Warning: A syntax error in .htaccess can cause a 500 error on the entire website. If you add rules, do so carefully and make a backup before modifying it.
Why it matters in hosting
Understanding this concept will help you make better decisions when managing your service. In practice, it relates to creating, maintaining or automating websites and applications hosted on the server. If it appears in a guide, the control panel or a support response, review the context before making changes.
Related articles
- HTML
- CSS
- JavaScript
- PHP
- Node.js