<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Mod Rewrite Tips and Tricks</title>
    <link rel="alternate" type="text/html" href="http://www.modrewrite.co.uk/" />
    <link rel="self" type="application/atom+xml" href="http://www.modrewrite.co.uk/atom.xml" />
    <id>tag:www.modrewrite.co.uk,2007-09-28://14</id>
    <updated>2007-10-10T23:20:36Z</updated>
    <subtitle>Harness the power of Apache&apos;s mod-rewrite</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Publishing Platform 4.01</generator>

<entry>
    <title>Blocking Specific User Agents</title>
    <link rel="alternate" type="text/html" href="http://www.modrewrite.co.uk/mod-rewrite/blocking-specific-user-agents.html" />
    <id>tag:www.modrewrite.co.uk,2007://14.2469</id>

    <published>2007-10-10T23:00:06Z</published>
    <updated>2007-10-10T23:20:36Z</updated>

    <summary>I came across a situation recently where a site was getting hammered by a couple of different ip addresses. The one thing they had in common was that they were all using the same User Agent, VoilaBot in this case....</summary>
    <author>
        <name>Niall Donegan</name>
        <uri>http://blog.moybella.net</uri>
    </author>
    
        <category term="apache" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="mod_rewrite" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="forbidden" label="forbidden" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="htaccess" label="htaccess" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="useragent" label="user agent" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modrewrite.co.uk/">
        <![CDATA[I came across a situation recently where a site was getting hammered by a couple of different ip addresses. The one thing they had in common was that they were all using the same User Agent, VoilaBot in this case. Instead of blocking each IP using <a href="http://www.netfilter.org/">IPTables</a>, the following was added to the .htaccess file:<br /><blockquote>RewriteEngine on<br />RewriteCond %{HTTP_USER_AGENT} VoilaBot<br />RewriteRule .* - [F,L]<br /></blockquote>Any client with "Voilabot" in the User Agent now gets a forbidden page.<br /><br />If you want to ban multiple User Agents, you can do the following:<br /><blockquote>RewriteEngine on<br />RewriteCond %{HTTP_USER_AGENT} UserAgent1 [OR]<br />RewriteCond %{HTTP_USER_AGENT} UserAgent2<br />RewriteRule .* - [F,L]<br /></blockquote><br /> ]]>
        
    </content>
</entry>

<entry>
    <title>Canonical Urls With Mod Rewrite</title>
    <link rel="alternate" type="text/html" href="http://www.modrewrite.co.uk/mod-rewrite/canonical-urls-with-mod-rewrite.html" />
    <id>tag:www.modrewrite.co.uk,2007://14.2450</id>

    <published>2007-10-03T08:00:00Z</published>
    <updated>2007-10-02T23:09:53Z</updated>

    <summary>It&apos;s not unusual to have multiple domains pointing at one site, possibly for brand protection or vanity domains.If these extra domains are simply added in as aliases of the main domain, they will all appear as separate sites to search...</summary>
    <author>
        <name>Niall Donegan</name>
        <uri>http://blog.moybella.net</uri>
    </author>
    
        <category term="apache" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="mod_rewrite" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="canonical" label="canonical" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="redirect" label="redirect" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="url" label="url" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modrewrite.co.uk/">
        <![CDATA[It's not unusual to have multiple domains pointing at one site, possibly for brand protection or vanity domains.<br /><br />If these extra domains are simply added in as aliases of the main domain, they will all appear as separate sites to search engines such as Google or Yahoo. This means that the various domains probably incur a duplicate content penalty.<br /><br />Fortunately, this is easy to get around. Presuming that your primary domain name is example.com, the following can be put at the top of the .htaccess file in your document root:<br /><blockquote><br />RewriteEngine on<br />RewriteCond %{HTTP_HOST} !^example\.com$ [NC]<br />RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]<br /></blockquote>The <b>RewriteCond</b> line checks to see if the HTTP_HOST¹ is NOT example.com. If this is the case it will do a permanent(301) redirect to http://example.com/$1, where $1 is the part that was after the HTTP_HOST.<br /><br />As written above, example.com will appear as the canonical url rather than www.example.com. If the user does enter www.example.com, they will get redirected to example.com. To change this behavior, add in the www in the third line.<br /><br />¹HTTP_HOST is the domain name that the user is using to access the site&nbsp; when the .htaccess file is called by Apache.<br />]]>
        
    </content>
</entry>

<entry>
    <title>Making the most of Apache</title>
    <link rel="alternate" type="text/html" href="http://www.modrewrite.co.uk/apache/making-the-most-of-apache.html" />
    <id>tag:www.modrewrite.co.uk,2007://14.2435</id>

    <published>2007-09-28T19:05:00Z</published>
    <updated>2007-09-28T19:06:00Z</updated>

    <summary>While I&apos;ll be adding tips and tricks that I&apos;ve learnt over the years one book that I&apos;d highly recommend is the Apache Cookbook.It&apos;s jam packed with really nice tips and tricks to get Apache to do exactly what you want...</summary>
    <author>
        <name>Michele Neylon</name>
        <uri>http://www.mneylon.com/blog/</uri>
    </author>
    
        <category term="apache" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="books" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="apache" label="apache" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="books" label="books" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="reading" label="reading" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="tips" label="tips" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modrewrite.co.uk/">
        <![CDATA[While I'll be adding tips and tricks that I've learnt over the years one book that I'd highly recommend is the Apache Cookbook.<br /><br />It's jam packed with really nice tips and tricks to get Apache to do exactly what you want no matter how crazy that may seem<br /><br /><span class="mt-enclosure mt-enclosure-amazon"><a href="http://www.amazon.co.uk/gp/redirect.html%3FASIN=0596001916%26tag=modrewrite-21%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0596001916%253FSubscriptionId=0E71RGK5Y5S5J82SE482"><img alt="Apache Cookbook" src="http://images.amazon.com/images/P/0596001916.01._SCLZZZZZZZ_SX175_.jpg" class="mt-image-right" style="margin: 0pt 0pt 20px 20px; float: right;" /></a></span><br /><br /> <div><br /></div>]]>
        
    </content>
</entry>

<entry>
    <title>Introducing Apache&apos;s Mod_Rewrite</title>
    <link rel="alternate" type="text/html" href="http://www.modrewrite.co.uk/apache/introducing-apaches-mod-rewrite.html" />
    <id>tag:www.modrewrite.co.uk,2007://14.2434</id>

    <published>2007-09-28T18:08:44Z</published>
    <updated>2007-09-28T18:12:55Z</updated>

    <summary>I would never claim to be an expert with Apache&apos;s mod_rewrite module, but I have come to use it over the years to perform a number of little tricks to make my life easier.What&apos;s this site about?Apache&apos;s mod_rewrite module and...</summary>
    <author>
        <name>Michele Neylon</name>
        <uri>http://www.mneylon.com/blog/</uri>
    </author>
    
        <category term="apache" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="iis" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="mod_rewrite" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="apache" label="apache" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mod_rewrite" label="mod_rewrite" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.modrewrite.co.uk/">
        <![CDATA[I would never claim to be an expert with Apache's mod_rewrite module, but I have come to use it over the years to perform a number of little tricks to make my life easier.<br /><br /><b>What's this site about?</b><br /><br />Apache's mod_rewrite module and how to make use of it.<br /><br /><b>Who is it aimed at?</b><br /><br />Webmasters of all skill levels.<br /><br /><b>Will these tips work with IIS?</b><br /><br />By default no, but there are some 3rd party ISAPI modules for IIS that emulate some of mod_rewrite's functionality<br /><br /><br />If anyone knows of any cool tricks using mod_rewrite and would like to contribute just pop me an email to let me know!<br /><br /><br /> ]]>
        
    </content>
</entry>

</feed>
