e.g. /old /new
# Generated by Toolora
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
# Strip trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [L,R=301]
# Custom redirects
Redirect 301 /old-page /new-page
Redirect 301 /foo /bar
</IfModule>
# Enable Gzip
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>
# Browser cache
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>How to use
Set your domain and host rules
Type your domain into the Domain field, then tick the rules you need: Force HTTPS, Remove www or Force www, and Strip trailing slash. The output pane rebuilds with every change.
Add custom 301 redirects
In the redirects box, put one mapping per line as old path, space, new path, like /old-page /new-page. Each valid line becomes a Redirect 301 directive in the output.
Copy the finished .htaccess
Tick Gzip compression and Browser cache headers if you want the performance blocks, then press the copy button and paste the result into the .htaccess file at your site root.
Why .htaccess Generator
- Visual builder for Apache .htaccess.
- Force HTTPS, manage www, strip trailing slashes, custom redirects.
- Plus gzip and browser-cache directives.