htaccess Basics in Apache

From the Apache cheat sheet ยท htaccess & URL Rewriting ยท verified Jul 2026

.htaccess Basics

Common .htaccess configurations

apache
# Enable rewrite engine
RewriteEngine On

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

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

# Custom error pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
๐Ÿ“ .htaccess provides directory-level config
๐Ÿ”’ Requires AllowOverride All in vhost
โšก Can impact performance if overused
๐ŸŽฏ Great for shared hosting environments

Continue with Apache

Save the full cheat sheet or work through every related task.

More Apache tasks

Back to the full Apache cheat sheet