<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: htaccess code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 01:51:55 GMT</pubDate>
    <description>DZone Snippets: htaccess code</description>
    <item>
      <title>no www</title>
      <link>http://snippets.dzone.com/posts/show/3061</link>
      <description>&lt;code&gt;&lt;br /&gt;RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]&lt;br /&gt;RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 30 Nov 2006 07:00:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3061</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Remove www from URLs.</title>
      <link>http://snippets.dzone.com/posts/show/2264</link>
      <description>This is important to implement for your search engine ranking. Google, for example, thinks www.domain.com is a different site from domain.com, and this can seriously impact where you rank in Google. There are other ways of doing this, but the below is the only one that doesn't spit back a 500 error on my server, for some reason.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;RewriteEngine On &lt;br /&gt;RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]&lt;br /&gt;RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 10 Jul 2006 14:48:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2264</guid>
      <author>nothingless (Sasha)</author>
    </item>
    <item>
      <title>slashdot protection</title>
      <link>http://snippets.dzone.com/posts/show/1957</link>
      <description>Replace aaa.bbb.ccc.ddd with your own IP (so you always get to your site).&lt;br /&gt;Replace www.yourdomain.com with your actual domain.&lt;br /&gt;&lt;br /&gt;Just don&#8217;t mess with the user_agent and query_string lines. Those ensure that the Coral servers themselves can retrieve your page when they need to.&lt;br /&gt;&lt;br /&gt;(Shamelessly stolen from http://ottodestruct.com/diggprotectionrules.txt)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;RewriteEngine on&lt;br /&gt;RewriteCond %{REMOTE_ADDR} !^aaa.bbb.ccc.ddd$&lt;br /&gt;RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx&lt;br /&gt;RewriteCond %{QUERY_STRING} !(^|&amp;)coral-no-serve$&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?digg\.com [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?slashdot\.org [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?slashdot\.com [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?fark\.com [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?somethingawful\.com [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?kuro5hin\.org [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?engadget\.com [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?boingboing\.net [OR]&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^http://(www\.)?del\.icio\.us&lt;br /&gt;RewriteRule ^(.*)$ http://www.yourdomain.com.nyud.net:8080$1 [R,L]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 23 Apr 2006 14:43:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1957</guid>
      <author>lordrich ()</author>
    </item>
    <item>
      <title>Banning bad bots</title>
      <link>http://snippets.dzone.com/posts/show/1935</link>
      <description>The following code is the contents of /banme/index.php.  This file is linked to from my main website but invisible to web browsers and disallowed in robots.txt.  Therefore, only bad bots will ever follow this link and when they do so they will get banned in .htaccess and their ip address will be emailed to webmaster@example.com.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$i = getenv('REMOTE_ADDR');&lt;br /&gt;$handle = fopen("../.htaccess", "a");&lt;br /&gt;fwrite($handle, "Deny from $i\n");&lt;br /&gt;fclose($handle);&lt;br /&gt;echo "You've just got $i banned from this domain.  You are a very bad person.";&lt;br /&gt;mail("webmaster@example.com", "Banned IP", "Deny from $i");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 18 Apr 2006 15:49:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1935</guid>
      <author>lordrich ()</author>
    </item>
    <item>
      <title>Apache htaccess authentication</title>
      <link>http://snippets.dzone.com/posts/show/1508</link>
      <description>For setting up a quick protected directory, put this in .htaccess&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;AuthName "Some Admin Area"&lt;br /&gt;AuthType Basic&lt;br /&gt;AuthUserFile /home/someclient/public_html/admin/.htpasswd&lt;br /&gt;require valid-user&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And then create the .htpasswd file via&lt;br /&gt;htpasswd -c .htpasswd someuser&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 17 Feb 2006 10:00:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1508</guid>
      <author>mvidberg ()</author>
    </item>
    <item>
      <title>Redirect port 80 to port 443 (ssl)</title>
      <link>http://snippets.dzone.com/posts/show/691</link>
      <description>&lt;code&gt;&lt;br /&gt;RewriteEngine On &lt;br /&gt;RewriteCond  %{SERVER_PORT} !^443$&lt;br /&gt;RewriteRule ^(.*)$ https://www.domain.de/folder/$1 [L,R]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 09 Sep 2005 18:34:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/691</guid>
      <author>beate (Beate)</author>
    </item>
    <item>
      <title>Parse HTML files as PHP</title>
      <link>http://snippets.dzone.com/posts/show/459</link>
      <description>Add this to your .htaccess file in Apache:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;AddType application/x-httpd-php .html&lt;/code&gt;</description>
      <pubDate>Wed, 06 Jul 2005 04:00:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/459</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>301 example.com to www.example.com</title>
      <link>http://snippets.dzone.com/posts/show/220</link>
      <description>&lt;code&gt;RewriteEngine On&lt;br /&gt;&lt;br /&gt;RewriteCond %{HTTP_HOST} !^(.*)\.example\.com$ [NC]&lt;br /&gt;RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]&lt;/code&gt;</description>
      <pubDate>Sat, 23 Apr 2005 18:01:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/220</guid>
      <author>Syam (Syam Kumar R.)</author>
    </item>
    <item>
      <title>Prevent yourself from getting Slashdotted</title>
      <link>http://snippets.dzone.com/posts/show/115</link>
      <description>Assuming you have mod_rewrite and AllowOverride activated, throw this in the .htaccess file for the directory you don't want to be Slashdotted:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;RewriteEngine On&lt;br /&gt;RewriteCond %{HTTP_REFERER} ^.*slashdot.*$&lt;br /&gt;RewriteRule .* - [F]&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This all assumes the editors actually check the links before posting the story, but this should reasonably mean no-one on Slashdot can link to you, even if it's a bit over the top.</description>
      <pubDate>Sun, 10 Apr 2005 10:43:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/115</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Build blacklist .htaccess file modified</title>
      <link>http://snippets.dzone.com/posts/show/101</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;# -*- coding: utf-8 -*-&lt;br /&gt;"""&lt;br /&gt;blacklist_builder.py&lt;br /&gt;Get the entries from a blacklist&lt;br /&gt;and print them to standard output&lt;br /&gt;"""&lt;br /&gt;import urllib2, re&lt;br /&gt;latest = urllib2.urlopen("http://www.unknowngenius.com/blog/blacklist/")&lt;br /&gt;prefix = 'RewriteEngine  on'&lt;br /&gt;suffix = 'RewriteRule /(.*) / [F,L]'&lt;br /&gt;str = [prefix]&lt;br /&gt;begin = "RewriteCond %{HTTP_REFERER} ^.*"&lt;br /&gt;for line in latest:&lt;br /&gt;	print '.',&lt;br /&gt;	str.append(begin + re.sub('(\s#:url:|\s#:regex-url:|\s#:rbl:)', ".*$ [OR,NC]", line))&lt;br /&gt;str.append(suffix)&lt;br /&gt;file('.htaccess', 'w').write('\n'.join(str))&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Use of list to speed up.&lt;br /&gt;&lt;br /&gt;Added prefix and suffix to make it a complete rewrite.</description>
      <pubDate>Sat, 09 Apr 2005 07:01:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/101</guid>
      <author>fgranger (Fran&#231;ois Granger)</author>
    </item>
  </channel>
</rss>
