<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ashesh Shrestha &#187; htaccess</title>
	<atom:link href="http://www.ashesh.com.np/tag/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ashesh.com.np</link>
	<description>Ashesh - Never ending</description>
	<lastBuildDate>Sat, 28 Aug 2010 17:39:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Deny visitors by IP address using .htaccess</title>
		<link>http://www.ashesh.com.np/deny-visitors-by-ip-address-usinghtaccess/</link>
		<comments>http://www.ashesh.com.np/deny-visitors-by-ip-address-usinghtaccess/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 13:24:03 +0000</pubDate>
		<dc:creator>Ashesh</dc:creator>
				<category><![CDATA[How to...]]></category>
		<category><![CDATA[Know more]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[ip address]]></category>

		<guid isPermaLink="false">http://www.ashesh.com.np/?p=1431</guid>
		<description><![CDATA[The visitor blocking facilities offered by the Apache Web Server enable us to deny access to specific visitors, or allow access to specific visitors. This is extremely useful for blocking unwanted visitors, or to only allow the web site owner access to certain sections of the web site, such as an administration area.To set-up visitors [...]


Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
<li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/' rel='bookmark' title='Permanent Link: Beginners Guide to .htaccess File with Examples'>Beginners Guide to .htaccess File with Examples</a></li>
<li><a href='http://www.ashesh.com.np/protecting-email-address-with-htaccess/' rel='bookmark' title='Permanent Link: Protecting email address with .htaccess'>Protecting email address with .htaccess</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Verdana; font-size: x-small;">The visitor blocking facilities offered by the Apache Web Server enable us to deny access to specific visitors, or allow access to specific visitors. This is extremely useful for blocking unwanted visitors, or to only allow the web site owner access to certain sections of the web site, such as an administration area.To set-up visitors restrictions and blocking, create a .htaccess file following the main instructions and guidance which includes the following text:<span><span id="more-1431"></span></span></p>
<p></span></p>
<table border="0" cellspacing="0" cellpadding="1" width="90%" bgcolor="#cccccc">
<tbody>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="10" width="100%" bgcolor="#ffffff">
<tbody>
<tr>
<td><span style="font-family: Arial; font-size: x-small;"><em> order allow,deny<br />
deny from 255.0.0.0<br />
deny from 123.45.6.<br />
allow from all </em></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; font-size: x-small;">The above lines tell the Apache Web Server to block visitors from the IP address &#8217;255.0.0.0&#8242; and &#8217;123.45.6.&#8217;, note the second IP address is missing the fourth set of digits, this means any IP address which matches the firth three set of digits will be blocked, e.g. &#8217;123.45.6.10&#8242; and &#8217;123.45.6.255&#8242; would be blocked.</p>
<p>To set-up blocking of all visitors except yourself, create a .htaccess file following the main instructions and guidance which includes the following text:</p>
<p></span></p>
<table border="0" cellspacing="0" cellpadding="1" width="90%" bgcolor="#cccccc">
<tbody>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="10" width="100%" bgcolor="#ffffff">
<tbody>
<tr>
<td><span style="font-family: Arial; font-size: x-small;"><em> order allow,deny<br />
allow from 255.0.0.0<br />
deny from all </em></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; font-size: x-small;">The above lines tell the Apache Web Server to block all visitors except those with the IP address &#8217;255.0.0.0&#8242;, which you should replace with your own IP address.</p>
<p>You may add any number of &#8216;deny from&#8217; and &#8216;allow from&#8217; records after the &#8216;order allow,deny&#8217;. Note the change from &#8216;allow from all&#8217; to &#8216;deny from all&#8217; on the bottom line, this is important and must be changed depending on your requirements. If you want to allow your visitor access, you would use &#8216;allow from all&#8217; and place &#8216;deny from&#8217; lines above.</p>
<p>Blocked visitors will be shown a &#8217;403 Forbidden&#8217; error message. You can customise this error message by following the &#8216;Error Documents&#8217; section of this article.</p>
<p></span></p>


<p>Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
<li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/' rel='bookmark' title='Permanent Link: Beginners Guide to .htaccess File with Examples'>Beginners Guide to .htaccess File with Examples</a></li>
<li><a href='http://www.ashesh.com.np/protecting-email-address-with-htaccess/' rel='bookmark' title='Permanent Link: Protecting email address with .htaccess'>Protecting email address with .htaccess</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ashesh.com.np/deny-visitors-by-ip-address-usinghtaccess/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do I redirect all links for www.domain.com to domain.com ?</title>
		<link>http://www.ashesh.com.np/how-do-i-redirect-all-links-for-www-domain-com-to-domain-com/</link>
		<comments>http://www.ashesh.com.np/how-do-i-redirect-all-links-for-www-domain-com-to-domain-com/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 14:22:29 +0000</pubDate>
		<dc:creator>Ashesh</dc:creator>
				<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.ashesh.com.np/?p=1379</guid>
		<description><![CDATA[Description of the problem: Your website can be accessed with www.domain.com and domain.com. Since Google penalizes this due to duplicated content reasons, you have to stick your domain to either www.domain.com or domain.com. But &#8211; since some links are outside of your website scope and the search engines already have indexed your website under both [...]


Related posts:<ol><li><a href='http://www.ashesh.com.np/how-to-redirect-a-webpage/' rel='bookmark' title='Permanent Link: how-to-redirect-a-webpage'>how-to-redirect-a-webpage</a></li>
<li><a href='http://www.ashesh.com.np/guide-to-htaccess-and-mod-rewrite/' rel='bookmark' title='Permanent Link: Guide to htaccess and mod_rewrite'>Guide to htaccess and mod_rewrite</a></li>
<li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<h3>Description of the problem:</h3>
<p>Your website can be accessed with www.domain.com and domain.com. Since Google penalizes this due to duplicated content reasons, you have to stick your domain to either www.domain.com or domain.com.<br />
But &#8211; since some links are outside of your website scope and the search engines already have indexed your website under both addresses, you can&#8217;t change that easily.<span id="more-1379"></span></p>
<h3>Solution:</h3>
<p>Do a 301 redirect for all http requests that are going to the wrong url.</p>
<h3>Example 1 &#8211; Redirect domain.com to www.domain.com</h3>
<p><code>RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]<br />
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] </code></p>
<h3>Example 2 &#8211; Redirect www.domain.com to domain.com</h3>
<p><code>RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]<br />
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] </code></p>


<p>Related posts:<ol><li><a href='http://www.ashesh.com.np/how-to-redirect-a-webpage/' rel='bookmark' title='Permanent Link: how-to-redirect-a-webpage'>how-to-redirect-a-webpage</a></li>
<li><a href='http://www.ashesh.com.np/guide-to-htaccess-and-mod-rewrite/' rel='bookmark' title='Permanent Link: Guide to htaccess and mod_rewrite'>Guide to htaccess and mod_rewrite</a></li>
<li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ashesh.com.np/how-do-i-redirect-all-links-for-www-domain-com-to-domain-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Guide to htaccess and mod_rewrite</title>
		<link>http://www.ashesh.com.np/guide-to-htaccess-and-mod-rewrite/</link>
		<comments>http://www.ashesh.com.np/guide-to-htaccess-and-mod-rewrite/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 13:45:11 +0000</pubDate>
		<dc:creator>Ashesh</dc:creator>
				<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.ashesh.com.np/?p=1376</guid>
		<description><![CDATA[Canonicalization The easiest htaccess trick is to make sure that your site doesn’t have any canonicalization issues on the homepage. A lot of websites suffer from poor search engine rankings by having a number of different versions of the homepage, for example: http://www.yoursite.com http://yoursite.com http://www.yoursite.com/index.html http://yoursite.com/index.html These pages are all seen as different urls, despite [...]


Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/' rel='bookmark' title='Permanent Link: Beginners Guide to .htaccess File with Examples'>Beginners Guide to .htaccess File with Examples</a></li>
<li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
<li><a href='http://www.ashesh.com.np/hide-php-extension-with-url-rewriting-using-htaccess/' rel='bookmark' title='Permanent Link: Hide .php extension with url rewriting using .htaccess'>Hide .php extension with url rewriting using .htaccess</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<h2>Canonicalization</h2>
<p>The easiest htaccess trick is to make sure that your site doesn’t have any canonicalization issues on the homepage.</p>
<p>A lot of websites suffer from poor search engine rankings by having a number of different versions of the homepage, for example:</p>
<p><code>http://www.yoursite.com</p>
<p>http://yoursite.com</p>
<p>http://www.yoursite.com/index.html</p>
<p>http://yoursite.com/index.html</code></p>
<p>These pages are all seen as different urls, despite them having exactly the same content in most cases. Google has got better at deciding which version to use over the past 12 months but you can still run into problems.</p>
<p>To solve this issue simply add the following to your htaccess file:<span id="more-1376"></span></p>
<p><code>Options +FollowSymLinks<br />
RewriteEngine on<br />
RewriteCond %{HTTP_HOST} ^yoursite.com<br />
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]<br />
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/<br />
RewriteRule ^index\.html$ http://www.yoursite.com/ [R=301,L]<br />
</code></p>
<p>This will redirect all versions to http://www.yoursite.com</p>
<h2>Changing html files to php</h2>
<p>Sometimes you might have a static html website and need to use php code on the html pages. Rather than redirecting all your html pages to the equivalent php versions you simply need to tell your server to parse html files as if they were php.</p>
<p><code><br />
AddHandler application/x-httpd-php .html<br />
</code></p>
<p>This works with any files so if you want to create dynamic xml or asp files that behave like php files you simply edit the code as required:</p>
<p><code><br />
AddHandler application/x-httpd-php .xml<br />
AddHandler application/x-httpd-php .asp<br />
</code></p>
<h2>Error pages</h2>
<p>Custom error pages can be set up in cpanel fairly easily, if you want to create a custom error page in htaccess instead use this line:</p>
<p><code><br />
ErrorDocument 404 http://www.yoursite.com/404.php<br />
</code></p>
<h2>Directory Indexes</h2>
<p>To avoid Google <a href="http://www.google.com/search?hl=en&amp;safe=off&amp;q=%22index+of%22%2B%22parent+directory%22">indexing your directory indexes</a> you might need to specify an index page for your directories. This is not required on some servers.</p>
<p><code><br />
DirectoryIndex index.php3<br />
</code></p>
<p>My preference is to redirect the directory index page to either the homepage or another suitable page. For example www.yoursite.com/images/ can normally be redirected to www.yoursite.com and www.yoursite.com/forum/ can normally be redirected to www.yoursite.com/forum/index.php</p>
<h2>Redirecting pages</h2>
<p>A nice simple use of htaccess is to redirect one page to another:</p>
<p><code><br />
redirect 301 /old-page.php http://www.yoursite.com/new-page.php<br />
</code></p>
<h2>Sending your feed to Feedburner</h2>
<p>If you want to switch your feed to the Feedburner service you will need to redirect your current feed to the new http://feeds.feedburner.com/yourfeed location.</p>
<p>The redirect needs to apply to all users except the Feedburner spider:</p>
<p><code><br />
RewriteCond %{HTTP_USER_AGENT} !FeedBurner<br />
RewriteRule ^your-feed\.xml$ http://feeds.feedburner.com/your-feed [R,L]<br />
</code></p>
<h2>Advanced hotlink protection</h2>
<p>If you want to block other websites from hotlinking your images, but allow indexing of your images in the Google, Yahoo and MSN image search engines, you should use the code below:</p>
<p><code><br />
RewriteEngine on<br />
RewriteCond %{HTTP_REFERER} .<br />
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?yoursite\. [NC]<br />
RewriteCond %{HTTP_REFERER} !google\. [NC]<br />
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]<br />
RewriteCond %{HTTP_REFERER} !msn\. [NC]<br />
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]<br />
RewriteCond %{REQUEST_URI} !^/hotlinker\.gif$<br />
RewriteRule \.(gif|jpg|png)$ /hotlinker.gif [NC,L]<br />
</code></p>
<p>The hotlinker.gif image is a custom image that you have created. I suggest using something like “This image was hotlinked from www.yoursite.com” and your logo.</p>
<p>My personal preference is to allow hotlinking but to implement a solution to make use of Google Images and hotlinkers to build links to your site.</p>
<h2>Create beautiful url’s with mod_rewrite</h2>
<p>The Apache rewrite engine is mainly used to turn dynamic url’s such as www.yoursite.com/product.php?id=123 into static and user friendly url’s such as www.yoursite.com/product/123</p>
<p><code><br />
RewriteEngine on<br />
RewriteRule ^product/([^/\.]+)/?$ product.php?id=$1 [L]<br />
</code></p>
<p>Another example, rewrite from:</p>
<p>www.yoursite.com/script.php?product=123 to www.yoursite.com/cat/product/123/</p>
<p><code><br />
RewriteRule cat/(.*)/(.*)/$ /script.php?$1=$2<br />
</code></p>
<h2>Removing query strings</h2>
<p>Some websites like to link to you by adding an query string, for example I could link to www.yoursite.com/index.php?source=blogstorm just so you know where your traffic came from. This creates duplicate content issue for your site so you really need to redirect back to your homepage:</p>
<p><code><br />
RewriteCond %{QUERY_STRING} ^source= RewriteRule (.*) /$1? [R=301,L]</code></p>


<p>Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/' rel='bookmark' title='Permanent Link: Beginners Guide to .htaccess File with Examples'>Beginners Guide to .htaccess File with Examples</a></li>
<li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
<li><a href='http://www.ashesh.com.np/hide-php-extension-with-url-rewriting-using-htaccess/' rel='bookmark' title='Permanent Link: Hide .php extension with url rewriting using .htaccess'>Hide .php extension with url rewriting using .htaccess</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ashesh.com.np/guide-to-htaccess-and-mod-rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protecting email address with .htaccess</title>
		<link>http://www.ashesh.com.np/protecting-email-address-with-htaccess/</link>
		<comments>http://www.ashesh.com.np/protecting-email-address-with-htaccess/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 12:15:25 +0000</pubDate>
		<dc:creator>Ashesh</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[sparm]]></category>

		<guid isPermaLink="false">http://www.ashesh.com.np/?p=1092</guid>
		<description><![CDATA[I hate spam, i received since i created my first email account and i am always interested in web development tricks and techniques for protecting email accounts. Recently i read book about email security and found there very interesting technique which allows users to send email to you while proveiding email harvester with completely false [...]


Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
<li><a href='http://www.ashesh.com.np/how-does-email-really-work/' rel='bookmark' title='Permanent Link: How does email really work'>How does email really work</a></li>
<li><a href='http://www.ashesh.com.np/increase-upload-file-size-in-php-using-htaccess/' rel='bookmark' title='Permanent Link: Increase upload file size in php using .htaccess'>Increase upload file size in php using .htaccess</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I hate spam, i received since i created my first email account and i am always interested in web development tricks and techniques for protecting email accounts. Recently i read book about email security and found there very interesting technique which allows users to send email to you while proveiding email harvester with completely false email address, i created variation of this trick which i will share here as well.</p>
<p>First method requires, to create a new fail let’s call it my_false_email@not_exisiting.com, if you are unsure then: YES, file should be named like a valid email address, any UNIX system should handle such file. Next thing we need to do is add following lines in .htaccess file:<span id="more-1092"></span></p>

<div class="wp_syntax"><div class="code"><pre class="htm" style="font-family:monospace;">&lt;filesMatch &quot;my_false_email@not_exisiting.com&quot;&gt;
ForceType application/x-httpd-php
&lt;/filesMatch&gt;</pre></div></div>

<p>Now our file will be executed as a PHP script, so open it and put there following script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: mailto:my_real_email@my_real_domain.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>When someone tries to access file my_false_email@not_exisiting.com default email software will open with your real email address. Such solution will never expose your email address to email harvester, however there are also few downsides of this method. First it requires to create additional file, second if someone wants to copy your email from the website and then use it, then obviously he will get the fake email and won’t be able to contact you.</p>
<p>First problem can be resolved by using my modification to this method, instead of creating additional file, we can use redirection, put in .htaccess following line:</p>
<p>RedirectMatch my_false_email@not_exisiting.com mailto:my_real_email@my_real_domain.com</p>
<p>Now whenever in the URL my_false_email@not_exisiting.com will be found, email application will open, just like when you would click link mailto:my_real_email@my_real_domain.com</p>
<p>The second problem is a bit more complicated because you can’t do much about, the safest way to avoid copying email from website is using such or similar anchors:<br />
< a href=”my_false_email@not_exisiting.com”>click to get my real email address< / a ></p>
<p>Also note that if you will use “mailto:” in href parameter, both of this techniques will NOT work at all, well i guess it is another downside of this method isn’t it?</p>


<p>Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/' rel='bookmark' title='Permanent Link: Beginners guide to .htaccess file with examples – Part II'>Beginners guide to .htaccess file with examples – Part II</a></li>
<li><a href='http://www.ashesh.com.np/how-does-email-really-work/' rel='bookmark' title='Permanent Link: How does email really work'>How does email really work</a></li>
<li><a href='http://www.ashesh.com.np/increase-upload-file-size-in-php-using-htaccess/' rel='bookmark' title='Permanent Link: Increase upload file size in php using .htaccess'>Increase upload file size in php using .htaccess</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ashesh.com.np/protecting-email-address-with-htaccess/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Beginners guide to .htaccess file with examples – Part II</title>
		<link>http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/</link>
		<comments>http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 16:30:47 +0000</pubDate>
		<dc:creator>Ashesh</dc:creator>
				<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.ashesh.com.np/?p=671</guid>
		<description><![CDATA[I hope you have gone through the examples listed in first part of this tutorial. If not, it’s here – [Beginners guide to .htaccess file with examples]. In this part, we will cover more examples with .htaccess file. Presenting custom error pages Use .htaccess file to present users with your custom pages for 401 [Authorization [...]


Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/' rel='bookmark' title='Permanent Link: Beginners Guide to .htaccess File with Examples'>Beginners Guide to .htaccess File with Examples</a></li>
<li><a href='http://www.ashesh.com.np/increase-upload-file-size-in-php-using-htaccess/' rel='bookmark' title='Permanent Link: Increase upload file size in php using .htaccess'>Increase upload file size in php using .htaccess</a></li>
<li><a href='http://www.ashesh.com.np/hide-php-extension-with-url-rewriting-using-htaccess/' rel='bookmark' title='Permanent Link: Hide .php extension with url rewriting using .htaccess'>Hide .php extension with url rewriting using .htaccess</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I hope you have gone through the examples listed in first part of this tutorial. If not, it’s here – <a href="http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/">[Beginners guide to .htaccess file with examples]</a>.</p>
<p>In this part, we will cover more examples with .htaccess file.</p>
<h4>Presenting custom error pages</h4>
<p>Use .htaccess file to present users with your custom pages for 401 [Authorization Required], 403 [Forbidden], 404 [not found] and 500 [Internal Server Error].<span id="more-671"></span></p>
<p><strong>Syntax:</strong><br />
ErrorDocument &lt; error-code &gt; &lt; location -of-custom-page&gt;</p>
<p><strong>Examples:</strong><br />
ErrorDocument 401 /401.html<br />
ErrorDocument 403 /403.html<br />
ErrorDocument 404 /404.html<br />
ErrorDocument 500 /500.html</p>
<p><img src="http://www.bloghash.com/wp-includes/images/smilies/icon_idea.gif" alt=":idea:" /> You can include some script in your customized pages to <strong>automatically send an email to you</strong> whenever those pages are called for. This way you will be notified every time a user encounters 404, 500 and other error messages.</p>
<h4>Redirecting your-domain.com[non-www] to www.your-domain.com</h4>
<p>From a search engine’s optimization point of view, we will use permanent redirection such that every time a request for non-www domain is made, it’s redirected and returns a status code of 301 [Permanent Redirect].</p>
<p><strong>RewriteEngine</strong> On<br />
<strong>RewriteCond</strong> %{HTTP_HOST} ^YourSite.com [nc]<br />
<strong>RewriteRule</strong> (.*) http://www.YourSite.com/$1 [R=301,L]</p>
<p>In the above lines, the first line tells the RewriteEngine to be On, second line mentions the Rewrite Condition and the last one is the rewrite rule.</p>
<h4>Limiting Number of simultaneous connections</h4>
<p>To limit the number of simultaneous connections to a directory or your entire site, use the below line. If you <strong>place it in a directory</strong> other than the root directory, then it will <strong>limit the connections</strong> to that <strong>directory and its sub-directories only</strong>. Placing it in htaccess file of <strong>root directory will implement it for entire site</strong>.</p>
<p><strong>Syntax:</strong><br />
MaxClients &lt; number-of-connections&gt;</p>
<p><strong>Examples:</strong><br />
MaxClients 40<br />
MaxClients 100</p>
<h4>Allow/Disallow certain visitors from accessing your site</h4>
<p>To accomplish it use the following lines. Look at the syntax first:</p>
<p><strong>Syntax:</strong><br />
Order allow,deny<br />
Deny from &lt; incoming -address &gt;<br />
Allow from &lt; incoming -address&gt;</p>
<p>The first line [Order allow,deny] tells what should be done first. The second line tells about denying incoming-addresses [could be a single IP, an IP block, domain name and all] and third line tells about the incoming-addresses [could be a single IP, an IP block, domain name and all] those should be allowed. <strong>If second line has ‘Deny all’</strong>, then you should <strong>change the order of allow,deny in the first line to deny,allow</strong>.</p>
<p><strong>To deny access to a single IP address and allow everyone else</strong><br />
Order allow,deny<br />
Deny from 100.100.100.1<br />
Allow from all</p>
<p><strong>To deny a block of IP address and allow everyone else. [Notice the second line]</strong><br />
Order allow,deny<br />
Deny from 100.100.100.<br />
Allow from all</p>
<p><strong>To deny a single IP address and allow everyone else. [Use it to block referrals from a specific domain]</strong><br />
Order allow,deny<br />
Deny from www.my-domain.com<br />
Allow from all</p>
<p><strong>To deny everyone else but yourself. [Notice the order of allow,deny has changed in first line and also appending more 'Allow from' lines at the end, which is valid]</strong></p>
<p>Order deny,allow<br />
Deny from all<br />
Allow from &lt; your-ip-address &gt;<br />
Allow from &lt; another-ip-address &gt;<br />
Allow from &lt; www.domain.com&gt;</p>
<h4>Specify Administrator’s email address in error message</h4>
<p>Using the line below in your htaccess file will display the conerned system administrator’s email address in the error messages. If you are not using custom pages for error messages, then this will help your visitors drop an email and let you know about problems.</p>
<p><strong>Syntax:</strong><br />
ServerAdmin &lt; a-valid-email-address&gt;</p>
<p><strong>Example:</strong><br />
ServerAdmin name@domain.com</p>
<p>I hope, that this tutorial will help you accomplish various tasks with ease. Your feedback, comments are welcome.</p>
<p><!-- google_ad_section_end --></p>


<p>Related posts:<ol><li><a href='http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/' rel='bookmark' title='Permanent Link: Beginners Guide to .htaccess File with Examples'>Beginners Guide to .htaccess File with Examples</a></li>
<li><a href='http://www.ashesh.com.np/increase-upload-file-size-in-php-using-htaccess/' rel='bookmark' title='Permanent Link: Increase upload file size in php using .htaccess'>Increase upload file size in php using .htaccess</a></li>
<li><a href='http://www.ashesh.com.np/hide-php-extension-with-url-rewriting-using-htaccess/' rel='bookmark' title='Permanent Link: Hide .php extension with url rewriting using .htaccess'>Hide .php extension with url rewriting using .htaccess</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples-%e2%80%93part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginners Guide to .htaccess File with Examples</title>
		<link>http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/</link>
		<comments>http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 16:23:14 +0000</pubDate>
		<dc:creator>Ashesh</dc:creator>
				<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.ashesh.com.np/?p=668</guid>
		<description><![CDATA[htaccess file allow us to make configuration changes on a per-directory basis. htaccess file works in Apache Web Server on both Linux/Unix and Windows operating system. This article has some basic .htaccess examples, such as htaccess redirect, to get you started with .htaccess right away. Just copy and paste the lines mentioned in this post [...]


Related posts:<ol><li><a href='http://www.ashesh.com.np/change-extension-of-web-pages-php-html/' rel='bookmark' title='Permanent Link: change extension of web pages .php .html'>change extension of web pages .php .html</a></li>
<li><a href='http://www.ashesh.com.np/increase-upload-file-size-in-php-using-htaccess/' rel='bookmark' title='Permanent Link: Increase upload file size in php using .htaccess'>Increase upload file size in php using .htaccess</a></li>
<li><a href='http://www.ashesh.com.np/how-to-make-robots-txt-file/' rel='bookmark' title='Permanent Link: How to make most out of Robots.txt File'>How to make most out of Robots.txt File</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>htaccess file</strong> allow us to make configuration changes on a per-<span id="IL_AD6">directory</span> basis. htaccess file works in <span id="IL_AD4">Apache Web Server</span> on both Linux/Unix and <span id="IL_AD1">Windows operating system</span>. This article has some basic <strong>.htaccess examples</strong>, such as <strong>htaccess redirect</strong>, to get you started with .htaccess right away. Just copy and paste the lines mentioned in this post below, with or without any modification, in your .<span id="IL_AD3">htaccess file</span> and it should work.</p>
<p>There are several things that developers, site owners and webmasters can do by using .htaccess file. Let’s look at some of them:<span id="more-668"></span></p>
<ul>
<li>Prevent directory browsing</li>
<li><span id="IL_AD7">Redirect</span> visitors from one page or directory to another</li>
<li><span id="IL_AD5">Password protection</span> for directories</li>
<li>Change the default index page of a directory</li>
<li><span id="IL_AD8">Prevent</span> hot-linking of images from <span id="IL_AD10">your website</span></li>
</ul>
<p>Since .htaccess file allows us to make changes on a per-directory basis, the following are valid places to put the .htaccess file in:</p>
<p><strong>/.htaccess</strong> [placing in root folder of the site]<br />
<strong>/content/.htaccess</strong> [placing in content folder]<br />
<strong>/content/html/images/.htaccess</strong> [in the images folder]</p>
<p><img src="http://www.bloghash.com/wp-includes/images/smilies/icon_idea.gif" alt=":idea:" /> Any command that you place in .htaccess file will affect it’s current directory where it is placed and also it’s sub-directories. You may put a .htaccess file in the root folder such that it will affect the whole site.</p>
<p><img src="http://www.bloghash.com/wp-includes/images/smilies/icon_idea.gif" alt=":idea:" /> <strong>Make a backup of your .htaccess file [if you have any] before you attempt any of the settings mentioned in this article</strong>. <strong>I must not be held responsible for any consequences that arises due to editing your .htaccess file</strong>. <img src="http://www.bloghash.com/wp-includes/images/smilies/icon_wink.gif" alt=";)" /></p>
<h2>Working with .htaccess files</h2>
<p>For creating and editing purpose, a normal text editor such as notepad will do. Alternatively, you can download a free copy of <a title="PSPad Editor" href="http://www.bloghash.com/2006/11/pspad-feature-rich-free-editor-for-programming/" target="_blank">PSPad</a> for easy editing. To be able to see files in your FTP software, you must enable settings in your FTP client to see hidden files on the remote server [applicable to your system as well]. When done editing, you can save the file with double quotes in windows. [Save file as ".htaccess", with double quotes]. This will save the file as .htaccess and will not prompt you for a file name as such. Let’s now move on to some common .htaccess file example.</p>
<h2>Allow/Deny Directory Browsing</h2>
<p>When directory browsing is on, people accessing a URL from your site with no index page or no pages at all, will see a list of files and folders.<strong> To prevent such directory access</strong>, just place the following line in your .htaccess file.</p>
<p><strong>IndexIgnore */*</strong></p>
<p>Many hosting companies, by default deny directory browsing and having said that, just in case you need <strong>to enable directory browsing</strong>, place the following line in your .htaccess file.</p>
<p><strong>Options +Indexes</strong></p>
<h2>Redirect visitors from one page or directory to another</h2>
<p>It’s quite simple. Look at the example lines below and place similar lines in your .htaccess file of the root folder and it will do the rest. [Remember to use permanent keyword <span id="IL_AD9">in the line</span> to tell the <span id="IL_AD2">search engines</span> that the old link has moved to the new link]. You can also setup multiple redirects using htaccess.</p>
<p><strong>Syntax</strong>: Redirect permanent [old directory/file name][<strong>space</strong>][new directory/file name]</p>
<p><strong>Redirect permanent</strong> /olddirectory  /newdirectory<br />
<strong>Redirect permanent</strong> /olddirectory  /somedirectory/newdirectory<br />
<strong>Redirect permanent</strong> /oldhtmlfile.htm /newhtmlfile.htm<br />
<strong>Redirect permanent</strong> /oldhtmlfile.htm http://your-domain.com/newhtmlfile.htm</p>
<p>All the above lines are valid. Just remember to replace the file/directory names with actual ones.</p>
<h2>Change the default index page of a directory or site</h2>
<p>Almost every hosting company will have index.htm, index.html, index.php, index.asp, default.asp, default.html as the default index page names in their web server settings. So, in case your site ordirectory does not has a file name which matches a name from the list above, chances are that your visitors will either see a list of all the files and folders [throughdirectory browsing] or will not see anything at all. To change the default index page’s name for a directory or the site, place the following line in the .htaccess file of the root folder  <strong>or</strong> the particular directory for which you want to change the index page’s name.</p>
<p><strong>DirectoryIndex</strong> homepage.htm<br />
<strong>DirectoryIndex</strong> somepage.htm</p>
<p>To have more names, put a space between file names and it will take into considerations all those file names as possible index page names. Which means, if it finds a filename matching a list of names you supplied [in the given order] in .htaccess, then it will open that page as the index page for thedirectory. The below line, with multiple names, is also a valid usage:</p>
<p><strong>DirectoryIndex</strong> homapage.html somepage.html myindexpage.html anything.html</p>
<p><img src="http://www.bloghash.com/wp-includes/images/smilies/icon_idea.gif" alt=":idea:" /> Remember, each entry must be in one line only.</p>
<h2>Preventing hot linking of images from your website</h2>
<p>If your website contains images which people from other websites are linking to and you get charged for the extra bandwidth, then placing the following lines willprevent any such image hot linking. Most of the hosting companies provide this feature in their control panel itself, such as CPanel. This trick requires <a href="http://www.bloghash.com/2006/12/apache-mod_rewrite-examples/">mod_rewrite engine</a> to be on in Apache on your web server.</p>
<p><strong>RewriteEngine on</strong><br />
<strong>RewriteCond</strong> %{HTTP_REFERER} !^$<br />
<strong>RewriteCond</strong> %{HTTP_REFERER} !^http://(www\.)?your-domain.com/.*$ [NC]<br />
<strong>RewriteRule</strong> .(gif|jpg)$ – [F]</p>
<p>In the above code, replace [your-domain] with your actual domain name [without www], and instead of (www.\), use your actual subdomain name (sub-domain.\)</p>
<h2>Prevent access to your .htaccess file (.htaccess security)</h2>
<p>This article would remain incomplete without mentioning this trick. <img src="http://www.bloghash.com/wp-includes/images/smilies/icon_wink.gif" alt=";)" /> To prevent visitors from viewing your .htaccess file, place the following lines in your file. Of course, by default most Apache installations will not show .htaccess file but just in case.</p>
<p>&lt;Files .htaccess&gt;<br />
order allow,deny<br />
deny from all<br />
&lt;/Files&gt;</p>
<p>More information and detailed documentation, visit <a title="htaccess help" href="http://httpd.apache.org/docs/2.2/howto/htaccess.html" target="_blank">Apache website</a>.</p>
<p>There’s also a <strong>second part</strong> to this tutorial – <a href="http://www.bloghash.com/2006/11/beginners-guide-to-htaccess-file-with-examples-part-ii/">Beginners guide to .htaccess file with examples – Part II</a> and you may also be interested in the <a href="http://www.bloghash.com/2006/12/apache-mod_rewrite-examples/">Apache mod_rewrite examples</a> for writing search engine friendly URLs.</p>


<p>Related posts:<ol><li><a href='http://www.ashesh.com.np/change-extension-of-web-pages-php-html/' rel='bookmark' title='Permanent Link: change extension of web pages .php .html'>change extension of web pages .php .html</a></li>
<li><a href='http://www.ashesh.com.np/increase-upload-file-size-in-php-using-htaccess/' rel='bookmark' title='Permanent Link: Increase upload file size in php using .htaccess'>Increase upload file size in php using .htaccess</a></li>
<li><a href='http://www.ashesh.com.np/how-to-make-robots-txt-file/' rel='bookmark' title='Permanent Link: How to make most out of Robots.txt File'>How to make most out of Robots.txt File</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ashesh.com.np/beginners-guide-to-htaccess-file-with-examples/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
