.htaccess – Changing .php to .html and Getting Rid of www

This is a good one to use if you’re building your website from scratch. This is not a good one to use with a Content Management System (CMS) like Joomla or WordPress. I know Joomla has its own core htaccess file as well as third party extensions like JoomSEF. I would imagine WordPress has similar options.

That being said, if you’re building a PHP site, this is a great way to hide the fact that this a PHP site and possibly causing hackers to overlook your site. There’s no SEO advantage to having a .html extension over a .php extension. The biggest drawback I can see to using this part of the script is if you commonly pass variable through your URLs (ie. filename.php?id=420&action=token). If that is the situation you are in, then you can simply strip that part out of the script.

The second feature of this script is eliminating the “www.” option to get to your site. When someone types in http://www.yoursite.com, it will automatically change to http://yoursite.com. This part of the script is important to SEO because it concentrates all of your indexed pages into a single domain, making it more relevant in the eyes of Google. It also makes it much easier to track with Google Analytics and helps to eliminate “self referrals” (when your own website shows up in Analytics as a referring site).
The Script

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^northernseo.com$ [NC]
RewriteRule ^(.*)$ http://northernseo.com/$1 [L,R=301]
Options +FollowSymlinks
RewriteRule ^(.*)\.html$ $1.php [nc]
UPDATE

This one is much better. It will take any page on your site and serve it without the www. The previous example would redirect all www. requests to the home page. If you have several pages indexed in any of the major search engines, that would be quite disruptive. This new script is seamless.

RewriteEngine On
RewriteBase /
RewriteCond ${HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^northernseo\.com
RewriteRule (.*)$ http://northernseo.com/$1 [L,R=301]

Leave a Reply

Your email address will not be published. Required fields are marked *