5 HTAccess file snippets you should keep handy

1) Make your URLs SEO-friendly and future-proof

CODE :
<Files ABC>
ForceType application/x-httpd-php5
</Files>

2) Apply tag rel=”canonical” to PDFs and images

CODE : <Files abc.pdf>
Header add Link ‘<http://www.123.co.uk/httest/pdf-abc.html>; rel=”canonical”‘
</Files>

<Files xyz.jpg>
Header add Link ‘<http://www.123.co.uk/httest/xyz-page.html>; rel=”canonical”‘
</Files>

3) Robots Directive

CODE :¬†Header set X-Robots-Tag “noindex, noarchive, nosnippet”

4) Different types of redirect

CODE :# Ensure www on all URLs.
RewriteCond %{HTTP_HOST} ^123.com [NC]
RewriteRule ^(.*)$ http://www.123.com/$1 [L,R=301]

# Ensure we are using HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Ensure all URLs have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

5) Custom 404 error page

CODE : ErrorDocument 404 /toolz404.html
# Can also do the same for other errors…

ErrorDocument 500 /toolz500.html

[SOURCES : http://moz.com/blog/htaccess-file-snippets-for-seos ]

Technology

Leave a Reply

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