htaccess
Last updated
.htaccess is a small configuration file used on Apache and LiteSpeed web servers to control how a website behaves, for example where to send visitors and who may enter.
It lives in the site's folder, and the server reads it on every request. Common uses are 301 redirects from old to new addresses, forcing https, blocking an IP address, setting custom error pages and adding caching rules. A single mistake in it can take the whole site down with a 500 error, so keep a copy before editing.
Examples
- Redirecting an old page to its new address with a 301.
- Forcing every visit to use https.
- Protecting a folder with a password.
Why it matters for your website
It is powerful and easy to break. Back it up first, change one thing at a time and test straight away. Note that some modern platforms, such as Laravel apps, use their own routing instead of long .htaccess files.