• This email address is being protected from spambots. You need JavaScript enabled to view it.

Using .htaccess to improve SEO.

 Using .htaccess to improve SEO.

 

In my previous article where I showed how to SEO optimize a Joomla installment, link here: SEO for Joomla.
The article became quite large and I could not dive deeper into the SEO aspect for .htaccess therefor I will dive deeper into .htaccess.
When it comes to web hosting or any kind of website .htaccess will be very important in terms of security what also ties into a higher SEO score.
The .htaccess file has been around since the dawn of time when it comes to HTTP/WWW protocols any can change the behavior of your site.
While configuring an Apache server through the http.conf itself it is rarely you will have access to that file on shared hosting solutions.
But do not worry the .htaccess file is almost as powerful at the http.conf file but it can be tricky to work with.
However in the long run understanding, this file will make your life much easier, and your website much better in the long run.
For Joomla users I have a pre-made .htaccess file you can download, the website you current viewing is configured with the same file.
--> Joomla .htaccess File <-- Remember to rename to .htaccess by removing the .txt extension when placing this in your ROOT.

 
A guide to the .htaccess file below with some pointers and configurations that might work for you, be sure to make a backup of your original file!
While working on my own SEO score I found numerous articles that cover the subject however with my previous article more information is needed.
Before we start to ensure that if you make an edit to check with your hosts help files there are small variations per host this can lead to errors.
I've added some snippets you will find handy to use, make sure to configure them according to your own taste and test results.

Redirect Everyone Except IP address to an alternate page.

ErrorDocument 403 http://www.yourdomain.com/
Order deny,allow
Deny from all
Allow from 208.113.134.190

Serve all .pdf files on your site using .htaccess and mod_rewrite with the php script.

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+)\.pdf$ /cgi-bin/pdf.php?file=$1 [L,NC,QSA]
Rewrite to www
RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico|sitemap\.xml)$
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

Rewrite to www dynamically.

RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]


Implementing a Caching Scheme with .htaccess

# year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 20 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
#2 hours
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
Header set Expires "Thu, 20 Apr 2010 20:00:00 GMT"
</FilesMatch>


Password Protect single file.

<Files login.php>
AuthName "Prompt"
AuthType Basic
AuthUserFile /web/askapache.com/.htpasswd
Require valid-user
</Files>


Password Protect multiple files.

<FilesMatch "^(private|phpinfo).*$"> AuthName "Development" AuthUserFile /.htpasswd AuthType basic Require valid-user </FilesMatch>
Prevent hotlinking.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ http://www.yourdomain.com/feed.


Operation PitchFork Strategic Battle-plan. Introduction:My own initiative to ponder on the options based on current data taking into account assets as described on the Operation