SEO Canonical Links redirects rewrites in htaccess without CMS

These are some methods you can use to rewrite URLs, redirect and make URLs SEO search Engine Optimised without using a CMS


#This should be added once above all other rewrites
RewriteEngine On

#Add trailing slashes – PAGE= exception
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} !PAGE.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$$1/ [L,R=301]
#if you want to add www. to all URLs, add it to the line above

#RewriteEngine On #Add www
RewriteCond %{HTTP_HOST} ^$
RewriteRule (.*)$1 [R=301]

#RewriteEngine On #Remove www
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

#RewriteEngine On #Rewrite index.html to index.php
RewriteBase /
RewriteRule ^index\.html?$ / [NC,R,L]

#RewriteEngine On #Rewrite index.php to /
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ [R=301,L]
#if you are removing www, remove it from the above line

#Trailing slash 2

RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([a-zA-Z0-9]+)
RewriteRule ^([a-zA-Z0-9]+)$ /%1/? [R=301,L]

#Rewrite URL

RewriteRule ^new-pretty-url/$ from-original-renamed.php
redirect 301 /original.php /new-pretty-url/

(if you’re making a new website, don’t worry about renaming all fines and redirecting from the original file names… )