Code Refresh
UPDATE: Please use the following URL instead now as your .htaccess code reference: http://bryanhadaway.com/dynamic-seo-friendly-htaccess-file/
Old
This will enforce forwarding / redirection to the www version of your pages, enforce clean URLs by removing index.php, index.html and index.htm and by removing query characters like ? where they don’t belong adding exceptions for folders/files where they are allowed and my favorite part, forwarding / redirecting 404 error pages to the page of your choosing, check it out:
Old Code
RewriteEngine on
RewriteBase /RewriteRule ^index\.(htm|html|php) http://www.website.com/ [R=301,L]
RewriteRule ^(.*)/index\.(htm|html|php) http://www.website.com/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} !^www\..*
RewriteRule ^.*$ http://www.website.com%{REQUEST_URI} [R=permanent,L]RewriteCond %{REQUEST_URI} !^/search-results.php
RewriteCond %{QUERY_STRING} !=”"
RewriteRule ^(.*)$ /$1? [R=301,L]ErrorDocument 404 sitemap.php
Bold parts are places you can edit. Simply paste the code in Notepad and then change website.com to your websites info, change search-results.php to the page you want to allow query strings on like a search results page, change sitemap.php to whatever page you want users to reach if they’ve reached your site in error, you can simply make it / if you want 404 errors to redirect to your homepage.
Save text file as .htaccess with “All Files” selected and then upload to the root folder of your website, this is often called public_html, just make sure it resides next to your index file.
Enjoy.
Thanks for reading, Bryan




