Click to call

Update: If you need some really advanced .htaccess tricks, I recommend you check out this page as it’s chalk full of anything you may need
http://perishablepress.com/stupid-htaccess-tricks/ 

 

htaccess files are the voodoo magic of re-writing URL’s so that they play well with search engines. What we are going for here are URL’s that are clean, easy to remember, don’t have any “junk” in them (www.mysite.com/services/?cntry=usa&refcode=12345045), and don’t repeat one-another. Keep in mind that these are to be used at the root of the directory to which they are being applied, for most of you that means the root of your entire website folder.

Here are some of the most common htaccess re-writes that we come across:

Force non-www to www version of your URL’s
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]

Redirect www version to non-www version
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]

Move a single page permanently (the only way that preserves SEO credit)
Redirect 301 /oldpage.html http://www.example.com/newpage.html

Redirect .html pages to their root pages. Use this if you have URL’s such as (www.mysite.com/index.html) and want to redirect it to just (www.mysite.com/)
RewriteRule ^index\.html$ / [NC,R,L]

Redirect .php pages to their root pages. Use this if you have URL’s such as (www.mysite.com/index.php) and want to redirect it to just (www.mysite.com/)
RewriteRule ^index\.php$ / [NC,R,L]

Redirect non-www version to www version AND remove .html extensions from URL’s

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule . http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . %1 [R=301,NE,L]