More Tools

.htaccess SEO Examples

Learn how to do a 301 redirect, force www or no www, always use https, and other SEO best practices with .htaccess

 

 

301 Redirect

Redirect 301 /old.html http://www.example.com/new-page.php
						

Redirect non-SSL to SSL

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
						

Force WWW

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
						

Force Trailing Slash

ReWriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$        /$1$2/ [L,R=301]
						

Remove File Extensions

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.php
# NOTE:  Replace php above with your preferred file extension. (html, htm, asp, etc...)
						
See also: Aleyda's htaccess generator