<?xml version="1.0" encoding="UTF-8"?>
<blog-post>
  <author-id type="integer">48617</author-id>
  <blog-comments-count type="integer">6</blog-comments-count>
  <blog-post-status-id type="integer">3</blog-post-status-id>
  <body-format>econsultancy_xml</body-format>
  <body-formatted>
  &lt;p&gt;
    &lt;strong&gt;The Basics&lt;/strong&gt;
    &lt;br /&gt;
    &lt;br /&gt;
.htaccess is the name of Apache's directory-level configuration file. When an .htaccess file is placed in a directory, Apache uses the configuration settings contained in it for that directory and any sub-directories.&lt;/p&gt;
  &lt;p&gt;The syntax used with .htaccess is quite basic yet .htaccess can be a powerful tool and is capable of controlling advanced, condition-based configurations.&lt;/p&gt;
  &lt;p&gt;For the official introduction to .htaccess, be sure to read the &lt;a href="http://httpd.apache.org/docs/1.3/howto/htaccess.html"&gt;tutorial&lt;/a&gt; at the Apache website. What follows are some common and basic .htaccess techniques that are very useful.&lt;/p&gt;
  &lt;p&gt;
    &lt;strong&gt;301 Redirects&lt;/strong&gt;
  &lt;/p&gt;
  &lt;p&gt;To make sure that all users go to www.yoursite.com even if they type in yoursite.com, use a 301 redirect.&lt;/p&gt;
  &lt;p&gt;Here's the .htaccess code:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;RewriteEngine on&lt;br /&gt;
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]&lt;br /&gt;
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]&lt;/em&gt;&lt;/p&gt;
  &lt;p&gt;301 redirects can be used in other ways as well and are &lt;a href="http://www.theinternetdigest.net/archive/301-redirects-seo.html"&gt;very important&lt;/a&gt; to SEO when you move pages.&lt;/p&gt;
  &lt;p&gt;For instance, if you have an old folder named &lt;em&gt;files&lt;/em&gt; whose contents are being moved or removed, you can avoid an SEO blunder by redirecting anyone who tries to access files in that folder to another file (or folder) as such:&lt;/p&gt;
  &lt;p&gt;
    &lt;em&gt;RewriteEngine on&lt;br /&gt;
RewriteRule ^files(.*)$ /some-other-page.html [L,R=301]&lt;/em&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;strong&gt;404 Redirect&lt;/strong&gt;
  &lt;/p&gt;
  &lt;p&gt;To redirect users who receive a 404 error to another page, you can set this in .htaccess:&lt;/p&gt;
  &lt;p&gt;
    &lt;em&gt;ErrorDocument 404 /notfound.html&lt;/em&gt;
  &lt;/p&gt;
  &lt;p&gt;This is a great way to reduce the risk that someone coming to your website via an invalid URL will be "&lt;em&gt;lost.&lt;/em&gt;"&lt;/p&gt;
  &lt;p&gt;
    &lt;strong&gt;Create SEO-Friendly URLs for Dynamic Pages&lt;/strong&gt;
  &lt;/p&gt;
  &lt;p&gt;If you have a dynamic page called &lt;em&gt;/news_articles.php&lt;/em&gt; and it is passed a numeric variable called id in the form of &lt;em&gt;/news_articles.php?id=5&lt;/em&gt;, you can use .htaccess to create a more SEO-friendly URL structure such as &lt;em&gt;/news-articles/5&lt;/em&gt;.&lt;/p&gt;
  &lt;p&gt;To accomplish this, use:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;RewriteEngine on&lt;br /&gt;
RewriteRule ^/?news-articles/([0-9]+)$ /news_articles\.php?id=$1&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Strip the Extension from Your Filenames&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;You'll notice that the SEO-friendly URL in the example above lacks a file extension.&lt;br /&gt;&lt;br /&gt;
For aesthetics and security, it's often desirable to be able to call static pages without the file extension. For example, the file &lt;em&gt;http://www.yoursite.com/about-us/management-team.php&lt;/em&gt; could be called via &lt;em&gt;http://www.yoursite.com/about-us/management-team&lt;/em&gt; instead.&lt;br /&gt;&lt;br /&gt;
To implement this, use this code:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;RewriteRule ^/?about-us/([a-z--]+)$ /about-us/$1\.php&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Protecting Images (and Other Files) From Leaching&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;If you host images or other multimedia files that others may be inclined to hotlink to at your expense, you can implement hotlink protection using .htaccess:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;RewriteEngine on&lt;br /&gt;
OnRewriteCond %{HTTP_REFERER} !^http://www.yoursite.com [NC]&lt;br /&gt;
RewriteCond %{HTTP_REFERER} !^http://yoursite.com [NC]&lt;br /&gt;
RewriteRule [^/]+.(gif|jpg)$ - [F]&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;
The code above will cause an image to break if the person trying to load it has been referred by a website other than yours.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;
These are but a few techniques that can be implemented with .htaccess. For a more thorough overview of .htaccess and how to use it, check out &lt;a href="http://www.javascriptkit.com/howto/htaccess.shtml"&gt;this guide&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;
There are also a couple of nifty tools &lt;a href="http://tools.dynamicdrive.com/userban/"&gt;here&lt;/a&gt; and &lt;a href="http://www.htaccesstools.com/"&gt;here&lt;/a&gt; that can generate certain .htaccess configurations for you.&lt;/p&gt;
</body-formatted>
  <body-unformatted>&lt;FormattedContent xmlns="http://www.e-consultancy.com/schema/formattedContent/"&gt;
  &lt;Paragraph&gt;
    &lt;Emphasis&gt;The Basics&lt;/Emphasis&gt;
    &lt;LineBreak /&gt;
    &lt;LineBreak /&gt;
.htaccess is the name of Apache's directory-level configuration file. When an .htaccess file is placed in a directory, Apache uses the configuration settings contained in it for that directory and any sub-directories.&lt;/Paragraph&gt;
  &lt;Paragraph&gt;The syntax used with .htaccess is quite basic yet .htaccess can be a powerful tool and is capable of controlling advanced, condition-based configurations.&lt;/Paragraph&gt;
  &lt;Paragraph&gt;For the official introduction to .htaccess, be sure to read the &lt;Link URL="http://httpd.apache.org/docs/1.3/howto/htaccess.html" Window="Self"&gt;tutorial&lt;/Link&gt; at the Apache website. What follows are some common and basic .htaccess techniques that are very useful.&lt;/Paragraph&gt;
  &lt;Paragraph&gt;
    &lt;Emphasis&gt;301 Redirects&lt;/Emphasis&gt;
  &lt;/Paragraph&gt;
  &lt;Paragraph&gt;To make sure that all users go to www.yoursite.com even if they type in yoursite.com, use a 301 redirect.&lt;/Paragraph&gt;
  &lt;Paragraph&gt;Here's the .htaccess code:&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Quote&gt;RewriteEngine on&lt;LineBreak /&gt;
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]&lt;LineBreak /&gt;
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]&lt;/Quote&gt;&lt;/Paragraph&gt;
  &lt;Paragraph&gt;301 redirects can be used in other ways as well and are &lt;Link URL="http://www.theinternetdigest.net/archive/301-redirects-seo.html" Window="Self"&gt;very important&lt;/Link&gt; to SEO when you move pages.&lt;/Paragraph&gt;
  &lt;Paragraph&gt;For instance, if you have an old folder named &lt;Quote&gt;files&lt;/Quote&gt; whose contents are being moved or removed, you can avoid an SEO blunder by redirecting anyone who tries to access files in that folder to another file (or folder) as such:&lt;/Paragraph&gt;
  &lt;Paragraph&gt;
    &lt;Quote&gt;RewriteEngine on&lt;LineBreak /&gt;
RewriteRule ^files(.*)$ /some-other-page.html [L,R=301]&lt;/Quote&gt;
  &lt;/Paragraph&gt;
  &lt;Paragraph&gt;
    &lt;Emphasis&gt;404 Redirect&lt;/Emphasis&gt;
  &lt;/Paragraph&gt;
  &lt;Paragraph&gt;To redirect users who receive a 404 error to another page, you can set this in .htaccess:&lt;/Paragraph&gt;
  &lt;Paragraph&gt;
    &lt;Quote&gt;ErrorDocument 404 /notfound.html&lt;/Quote&gt;
  &lt;/Paragraph&gt;
  &lt;Paragraph&gt;This is a great way to reduce the risk that someone coming to your website via an invalid URL will be "&lt;Quote&gt;lost.&lt;/Quote&gt;"&lt;/Paragraph&gt;
  &lt;Paragraph&gt;
    &lt;Emphasis&gt;Create SEO-Friendly URLs for Dynamic Pages&lt;/Emphasis&gt;
  &lt;/Paragraph&gt;
  &lt;Paragraph&gt;If you have a dynamic page called &lt;Quote&gt;/news_articles.php&lt;/Quote&gt; and it is passed a numeric variable called id in the form of &lt;Quote&gt;/news_articles.php?id=5&lt;/Quote&gt;, you can use .htaccess to create a more SEO-friendly URL structure such as &lt;Quote&gt;/news-articles/5&lt;/Quote&gt;.&lt;/Paragraph&gt;
  &lt;Paragraph&gt;To accomplish this, use:&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Quote&gt;RewriteEngine on&lt;LineBreak /&gt;
RewriteRule ^/?news-articles/([0-9]+)$ /news_articles\.php?id=$1&lt;/Quote&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Emphasis&gt;Strip the Extension from Your Filenames&lt;/Emphasis&gt;&lt;/Paragraph&gt;
  &lt;Paragraph&gt;You'll notice that the SEO-friendly URL in the example above lacks a file extension.&lt;LineBreak /&gt;&lt;LineBreak /&gt;
For aesthetics and security, it's often desirable to be able to call static pages without the file extension. For example, the file &lt;Quote&gt;http://www.yoursite.com/about-us/management-team.php&lt;/Quote&gt; could be called via &lt;Quote&gt;http://www.yoursite.com/about-us/management-team&lt;/Quote&gt; instead.&lt;LineBreak /&gt;&lt;LineBreak /&gt;
To implement this, use this code:&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Quote&gt;RewriteRule ^/?about-us/([a-z--]+)$ /about-us/$1\.php&lt;/Quote&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Emphasis&gt;Protecting Images (and Other Files) From Leaching&lt;/Emphasis&gt;&lt;/Paragraph&gt;
  &lt;Paragraph&gt;If you host images or other multimedia files that others may be inclined to hotlink to at your expense, you can implement hotlink protection using .htaccess:&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Quote&gt;RewriteEngine on&lt;LineBreak /&gt;
OnRewriteCond %{HTTP_REFERER} !^http://www.yoursite.com [NC]&lt;LineBreak /&gt;
RewriteCond %{HTTP_REFERER} !^http://yoursite.com [NC]&lt;LineBreak /&gt;
RewriteRule [^/]+.(gif|jpg)$ - [F]&lt;/Quote&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;
The code above will cause an image to break if the person trying to load it has been referred by a website other than yours.&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Emphasis&gt;Summary&lt;/Emphasis&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;
These are but a few techniques that can be implemented with .htaccess. For a more thorough overview of .htaccess and how to use it, check out &lt;Link URL="http://www.javascriptkit.com/howto/htaccess.shtml" Window="Self"&gt;this guide&lt;/Link&gt;.&lt;LineBreak /&gt;&lt;LineBreak /&gt;
There are also a couple of nifty tools &lt;Link URL="http://tools.dynamicdrive.com/userban/" Window="Self"&gt;here&lt;/Link&gt; and &lt;Link URL="http://www.htaccesstools.com/" Window="Self"&gt;here&lt;/Link&gt; that can generate certain .htaccess configurations for you.&lt;/Paragraph&gt;
&lt;/FormattedContent&gt;</body-unformatted>
  <created-at type="datetime">2008-08-26T07:10:00+01:00</created-at>
  <enabled-blog-comments-count type="integer">3</enabled-blog-comments-count>
  <expertise-level-id type="integer">1</expertise-level-id>
  <extract-format>econsultancy_xml</extract-format>
  <extract-formatted>
  &lt;p&gt;
    &lt;strong&gt;If your website is hosted on an &lt;a href="http://www.apache.org/"&gt;Apache&lt;/a&gt; web server, .htaccess is a great way to create SEO-friendly URLs, take care of issues that can harm SEO and make your life as a webmaster more convenient.&lt;/strong&gt;
  &lt;/p&gt;
</extract-formatted>
  <extract-unformatted>&lt;FormattedContent xmlns="http://www.e-consultancy.com/schema/formattedContent/"&gt;
  &lt;Paragraph&gt;
    &lt;Emphasis&gt;If your website is hosted on an &lt;Link URL="http://www.apache.org/" Window="Self"&gt;Apache&lt;/Link&gt; web server, .htaccess is a great way to create SEO-friendly URLs, take care of issues that can harm SEO and make your life as a webmaster more convenient.&lt;/Emphasis&gt;
  &lt;/Paragraph&gt;
&lt;/FormattedContent&gt;</extract-unformatted>
  <featured type="boolean">false</featured>
  <id type="integer">2723</id>
  <learn-more-formatted>&lt;p&gt;Econsultancy has published an &lt;strong&gt;&lt;a href="http://econsultancy.com/reports/search-engine-optimization-seo-best-practice-guide"&gt;SEO Best Practice Guide&lt;/a&gt;&lt;/strong&gt;, a comprehensive report about search engine optimization written by Dr Dave Chaffey which has been described as the 'SEO Bible'. We have also published a &lt;strong&gt;&lt;a href="http://econsultancy.com/reports/sem-search-engine-optimisation-seo-business-case"&gt;business case&lt;/a&gt;&lt;/strong&gt; for SEO and a &lt;strong&gt;&lt;a href="http://econsultancy.com/reports/sem-seo-request-for-proposal-rfp"&gt;Request for Proposal template file&lt;/a&gt;&lt;/strong&gt; for those looking to hire an SEO agency.&lt;/p&gt;</learn-more-formatted>
  <learn-more-unformatted>&lt;p&gt;Econsultancy has published an &lt;strong&gt;&lt;a href="http://econsultancy.com/reports/search-engine-optimization-seo-best-practice-guide"&gt;SEO Best Practice Guide&lt;/a&gt;&lt;/strong&gt;, a comprehensive report about search engine optimization written by Dr Dave Chaffey which has been described as the 'SEO Bible'. We have also published a &lt;strong&gt;&lt;a href="http://econsultancy.com/reports/sem-search-engine-optimisation-seo-business-case"&gt;business case&lt;/a&gt;&lt;/strong&gt; for SEO and a &lt;strong&gt;&lt;a href="http://econsultancy.com/reports/sem-seo-request-for-proposal-rfp"&gt;Request for Proposal template file&lt;/a&gt;&lt;/strong&gt; for those looking to hire an SEO agency.&lt;/p&gt;</learn-more-unformatted>
  <legacy-article-id type="integer">366218</legacy-article-id>
  <name>Basic .htaccess tricks for SEO and convenience</name>
  <private type="boolean">false</private>
  <published-at type="datetime">2008-09-01T08:45:00+01:00</published-at>
  <slug>basic-htaccess-tricks-for-seo-and-convenience</slug>
  <tweetbacks-updated-at type="datetime">2009-04-30T00:58:50+01:00</tweetbacks-updated-at>
  <unpublished-at type="datetime" nil="true"></unpublished-at>
  <updated-at type="datetime">2009-10-13T09:46:14+01:00</updated-at>
  <views-count type="integer">1703</views-count>
</blog-post>
