Basic Use of .htaccess file
- Set up redirects (301, 302)
- Re-write URLs (pretty URLs)
- Restrict access (IP blocking, password protection)
- Set custom error pages (404, 403, etc.)
- Force HTTPS
- Enable caching
- Modify PHP settings (if allowed by the server)
Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect from old page to new page
Redirect 301 /old-page.html https://example.com/new-page.html
Custom 404 Page
ErrorDocument 404 /custom-404.html
Prevent directory listing
Options -Indexes
Enable gzip compression
AddOutputFilterByType DEFLATE text/html text/css application/javascript