<?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>Roshan Bhattarai's Blog -  A blog about PHP, Ajax, JavaScript, CSS and Web 2.0 &#187; htaccess</title>
	<atom:link href="http://roshanbh.com.np/category/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>http://roshanbh.com.np</link>
	<description>Useful Tutorials, Scripts , Tips, and Resources for all PHP and Ajax beginners and experts .</description>
	<lastBuildDate>Thu, 10 Jun 2010 11:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to redirect browser to https (ssl) in php</title>
		<link>http://roshanbh.com.np/2008/05/redirect-browser-https-ssl-php.html</link>
		<comments>http://roshanbh.com.np/2008/05/redirect-browser-https-ssl-php.html#comments</comments>
		<pubDate>Fri, 02 May 2008 12:12:17 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=96</guid>
		<description><![CDATA[Most of the e-commerce website uses payment gateway for online payment. And, those sites uses SSL (secure socket layer) connection to transfer data to and from the payment gateway. In the common scenario, most of the sites uses &#8220;http&#8221; protocol and you can see &#8220;http&#8221; in the browser&#8217;s address bar. But in the above scenario,we [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F05%2Fredirect-browser-https-ssl-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F05%2Fredirect-browser-https-ssl-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Most of the e-commerce website uses payment gateway for online payment. And, those sites  uses SSL (secure socket layer) connection to transfer data to and from the payment gateway.</p>
<p><span id="more-96"></span></p>
<p align="justify">In the common scenario, most of the sites uses &#8220;http&#8221; protocol and you can see &#8220;http&#8221; in the browser&#8217;s address bar. But in the above scenario,we need to redirect the browser to &#8220;https&#8221; which means that &#8220;Hypertext Transfer Protocol over Secure Socket Layer&#8221;.</p>
<p align="justify">Ok let&#8217;s see a real example, type &#8220;http://www.gmail.com&#8221; in browser after a while the &#8220;http&#8221; gets converted to &#8220;https&#8221; in address bar, which means this site is transferring the data over SSL protocal.</p>
<h4>How to redirect the browser to https when site is using http protocal in PHP?</h4>
<p align="justify">First of all, you should know that SSL must be installed in the server. To redirect the browser to &#8220;https&#8221; , we must know that the site is using SSL or not at the moment. And for this, there is a server variable in PHP called &#8220;HTTPS&#8221;. $_SERVER['HTTPS'] returns &#8220;on&#8221; values when the site is using SSL connection.</p>
<h4>Function to redirect the browser to &#8220;https&#8221; in PHP</h4>
<pre class="prettyprint" style="overflow:auto ">function redirectToHTTPS()
{
  if($_SERVER['HTTPS']!="on")
  {
     $redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     header("Location:$redirect");
  }
}
</pre>
<p align="justify">Above function is quite simple, you can call the function in that page where you&#8217;ve to redirect the browser to &#8220;https&#8221; .This function will preserver you script file name and query string in browser.</p>
<h4>Redirecting whole website to &#8220;https&#8221; using .htaccess</h4>
<p align="justify">You can call the above function in each and every page to redirect the browser to &#8220;https&#8221;. But rather than doing so it will be better to write three line of code in .htaccess file to redirect the whole website to use SSL connection throughout the pages.</p>
<pre class="prettyprint" style="overflow:auto">  RewriteEngine On
  RewriteCond %{HTTPS} !on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</pre>
<p align="justify">Just copy and paste the above code in .htaccess file then the whole website will be redirected to &#8220;https&#8221; when the browser is opened in &#8220;http&#8221; mode. The browser just get redirected using <a href="http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html">url rewriting in .htaccess</a>.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=96&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/05/redirect-browser-https-ssl-php.html/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Change default directory page using .htaccess</title>
		<link>http://roshanbh.com.np/2008/04/change-default-page-htaccess.html</link>
		<comments>http://roshanbh.com.np/2008/04/change-default-page-htaccess.html#comments</comments>
		<pubDate>Mon, 21 Apr 2008 15:27:16 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/change-default-page-htaccess.html</guid>
		<description><![CDATA[I know you guzy all know about index file. This is the default file which is executed in the web server. For example, if you type&#8221;http://roshanbh.com.np&#8221; in this the browser, the &#8220;index.php&#8221; gets loaded first. This &#8220;index.php&#8221; file is commonly know as directory index file. Basically , the default executed file in the web directory [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F04%2Fchange-default-page-htaccess.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F04%2Fchange-default-page-htaccess.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">I know you guzy all know about index file. This is the default file which is executed in the web server. For example, if you type&#8221;http://roshanbh.com.np&#8221; in this the browser, the &#8220;index.php&#8221; gets loaded first. This &#8220;index.php&#8221; file is commonly know as directory index file.</p>
<p><span id="more-97"></span></p>
<p align="justify">Basically , the default executed file in the web directory starts with &#8220;index&#8221; such as &#8220;index.php&#8221;, &#8220;index.htm&#8221;, &#8220;index.html&#8221;, &#8220;index.aspx&#8221; etc.</p>
<p align="justify">Last time in one server, I&#8217;ve faced a problem. &#8220;index.html&#8221; as getting executed by default but &#8220;index.php&#8221; as not getting executed.In such kind of scenario, we may need to change the default file to be executed in the web directory.</p>
<p align="justify"><strong>Changing Default Directory index page using .htaccess </strong></p>
<p align="justify">The default directory index pages are defined in the apache&#8217;s configuration file and it can be override from .htaccess file. To do so put the following code in the .htaccess file,</p>
<pre class="prettyprint" style="overflow: auto">DirectoryIndex index.html index.htm index.php index.cgi</pre>
<p align="justify">Remember that you can also append the other names of files in the DirectoryIndex directive and the order of the above &#8220;DirectoryIndex&#8221; directive determines the order of index file in web directory.</p>
<p align="justify">First of all, &#8220;index.html&#8221; file is looked inside directory and if that file is not found then &#8220;index.htm&#8221; file is looked and if that is also not found then again seek for &#8220;index.php&#8221; and so on. If any file defined above directive can&#8217;t be found in the directory, then web server just list the files inside that directory if the directory listing is enabled. You can also <a href="http://roshanbh.com.np/2008/03/prevent-directory-listing-htaccess.html" target="_blank">prevent the directory listing</a> using .htaccess file.</p>
<p align="justify">&nbsp;</p>
<p><!--wsa:post-google-ads--></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=97&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/04/change-default-page-htaccess.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to check and enable mod_rewrite module in apache</title>
		<link>http://roshanbh.com.np/2008/04/check-enable-mod_rewrite-apache.html</link>
		<comments>http://roshanbh.com.np/2008/04/check-enable-mod_rewrite-apache.html#comments</comments>
		<pubDate>Mon, 07 Apr 2008 05:42:14 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[url rewriting]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/check-enable-mod_rewrite-apache.html</guid>
		<description><![CDATA[Well, I&#8217;ve got around 15 emails asking from readers, how to check the mod_rewrite module in apache and enable mod_rewrite module in apache after reading two most of the popular post of this blog 5 useful url rewriting examples and hide .php extension with url rewriting. How to check weather mod_rewrite module is enabled or [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F04%2Fcheck-enable-mod_rewrite-apache.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F04%2Fcheck-enable-mod_rewrite-apache.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Well, I&#8217;ve got around 15 emails asking from readers, how to check the mod_rewrite module in apache and enable mod_rewrite module in apache after reading two most of the popular post of this blog <a title="url rewriting example" href="http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html" target="_blank">5 useful url rewriting examples</a> and <a title="url rewriting php" href="http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html" target="_blank">hide .php extension with url rewriting</a>.<br />
<span id="more-79"></span><br />
<strong>How to check weather mod_rewrite module is enabled or not?<br />
</strong><br />
Well there are lots of technique to check this but I&#8217;ll show you a very  simple technique to check weather mod_rewrite module is enabled or not in you web server.</p>
<p align="justify"><strong>1) </strong>Type <span style="color: #000080;">&lt;?php phpinfo(); ?&gt;</span> in a php file and save it and run that file in the server.<br />
<strong> 2) </strong>And now you can the list of information, just search the word &#8220;mod_rewrite&#8221; from the browser&#8217;s search menu<br />
<strong> 3)</strong> If it is found under the &#8220;<span style="color: #000080;">Loaded Modules</span>&#8221; section then this module is already loaded as you see in the picture below, otherwise you need to go to the next step for enabling mod_rewrite module.</p>
<pre style="display: block"><a title="mod_rewrite.gif" href="http://roshanbh.com.np/wp-content/uploads/2008/04/mod_rewrite.gif"><img src="http://roshanbh.com.np/wp-content/uploads/2008/04/mod_rewrite.thumbnail.gif" border="0" alt="check mod rewrite module" width="128" height="79" /></a></pre>
</p>
<p align="justify"><strong>How to enable mod_rewrite module in apache in xampp, wamp?</strong></p>
<p align="justify">Now, I&#8217;ll show you how to enable how to mod_rewrite module in apache installed under windows environment.<br />
<strong> 1) </strong>Find the &#8220;<span style="color: #333399;">httpd.conf</span>&#8221; file under the &#8220;conf&#8221; folder inside the Apache&#8217;s installation folder.<br />
<strong> 2)</strong> Find the following line &#8220;<span style="color: #333399;">#LoadModule rewrite_module modules/mod_rewrite.so</span>&#8221; in the &#8220;<span style="color: #333399;">httpd.conf</span>&#8221; file.You can do this easily by searching the keyword &#8220;mod_rewrite&#8221; from find menu.<br />
<strong> 3) </strong>Remove the &#8220;<span style="color: #333399;">#</span>&#8221; at the starting of the line, &#8220;<span style="color: #333399;">#</span>&#8221;  represents that line is commented.<br />
<strong> 4) </strong>Now  restart the apache server.<br />
<strong> 5) </strong>You can see now &#8220;mod_rewrite&#8221; in the Loaded Module section while doing &#8220;phpinfo()&#8221;.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=79&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/04/check-enable-mod_rewrite-apache.html/feed</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>5 useful url rewriting examples using .htaccess</title>
		<link>http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html</link>
		<comments>http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html#comments</comments>
		<pubDate>Tue, 11 Mar 2008 04:10:43 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[url rewriting]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html</guid>
		<description><![CDATA[If you are looking for the examples of URL rewriting then this post might be useful for you. In this post, I&#8217;ve given five useful examples of URL rewriting using .htacess. If you don&#8217;t know something about url rewriting then please check my older post about url rewriting using .htaccess. Now let&#8217;s look at the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F03%2Furl-rewriting-examples-htaccess.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F03%2Furl-rewriting-examples-htaccess.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">If you are looking for the examples of URL rewriting then this post might be useful for you. In this post, I&#8217;ve given five useful examples of URL rewriting using .htacess. If you don&#8217;t know something about url rewriting then please check my older post about <a href="http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html" title="url rewriting using htaccess">url rewriting using .htaccess</a>.</p>
<p><span id="more-42"></span></p>
<p align="justify">Now let&#8217;s look at the examples</p>
<p><strong>1)Rewriting product.php?id=12 to  product-12.html</strong></p>
<p align="justify">It is a simple redirection in which .php extension is hidden from the browser&#8217;s address bar and dynamic url (containing &#8220;?&#8221; character) is converted into a static URL.</p>
<p><font color="#800000">RewriteEngine on<br />
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1</font></p>
<p><strong>2) Rewriting product.php?id=12 to  product/ipod-nano/12.html</strong></p>
<p>SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.</p>
<p><font color="#800000">RewriteEngine on<br />
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2</font></p>
<p><strong>3) Redirecting non www URL to www URL</strong></p>
<p align="justify">If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about <a href="http://roshanbh.com.np/2007/12/301-redirect-in-php-and-htaccess.html" title="301 redirect in PHP">SEO friendly redirect (301) redirect in php and .htaccess.</a></p>
<p><font color="#800000">RewriteEngine On<br />
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$<br />
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]</font></p>
<p><strong>4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz</strong></p>
<p align="justify"> Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e  http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.</p>
<p><font color="#800000">RewriteEngine On<br />
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1<br />
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1</font></p>
<p><strong>5) Redirecting the domain to a new subfolder of inside public_html.</strong></p>
<p align="justify">Suppose the you&#8217;ve redeveloped your site and all the new development reside inside the &#8220;new&#8221; folder of inside root folder.Then the new development of the website can be accessed like &#8220;test.com/new&#8221;. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it  under the root folder of the website. In result, www.test.com point out to the files inside  &#8220;new&#8221; folder.</p>
<p><strong>  </strong></p>
<p><font color="#800000">RewriteEngine On<br />
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]<br />
RewriteCond %{HTTP_HOST} ^www\.test\.com$<br />
RewriteCond %{REQUEST_URI} !^/new/<br />
RewriteRule (.*)   /new/$1  </font></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=42&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html/feed</wfw:commentRss>
		<slash:comments>126</slash:comments>
		</item>
		<item>
		<title>Prevent Directory Listing using .htaccess</title>
		<link>http://roshanbh.com.np/2008/03/prevent-directory-listing-htaccess.html</link>
		<comments>http://roshanbh.com.np/2008/03/prevent-directory-listing-htaccess.html#comments</comments>
		<pubDate>Sun, 09 Mar 2008 05:39:54 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[directory listing]]></category>
		<category><![CDATA[prevetion]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/03/prevent-directory-listing-htaccess.html</guid>
		<description><![CDATA[What is directory listing ? As we know, most of the website contains &#8220;images&#8221; folder inside the root folder. If we type &#8220;www.somesite.com/images&#8221; in the browser and it shows the listing of the files in the browser like the picture below which means that directory listing is allowed on that web server. It&#8217;s better not [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F03%2Fprevent-directory-listing-htaccess.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F03%2Fprevent-directory-listing-htaccess.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>What is directory listing ?</strong></p>
<p align="justify">As we know, most of the website contains &#8220;images&#8221; folder inside the root folder. If we type &#8220;www.somesite.com/images&#8221; in the browser and it shows the listing of the files in the browser like the picture below which means that directory listing is allowed on that web server. It&#8217;s better not to show the files inside the directory of the web sever for the security purpose. </p>
<p><span id="more-60"></span></p>
<p align="justify"> <a href="http://roshanbh.com.np/wp-content/uploads/2008/03/directory-listing.gif" title="directory-listing.gif"><img src="http://roshanbh.com.np/wp-content/uploads/2008/03/directory-listing.thumbnail.gif" alt="prevent directory listing using htaccess" align="left" border="0" /></a></p>
<p align="justify"> <strong>Why and what is prevent directory listing ?</strong><br />
Most of the web server are configured in such a way that it doesn&#8217;t show the listing of the directory but some of them are not.In some cases, you don&#8217;t want to allow users to view the files of the particular directry in such a direct way and prevent the listing of that directory.</p>
<p><strong>How to prevent directory listing ?</strong>
</p>
<p align="justify">Put the any one of following code into the .htaccess file</p>
<p align="justify"><font color="#800000">Options -Indexes</font><br />
or<br />
<font color="#800000">IndexIgnore *</font>
</p>
<p align="justify">If you place that .htaccess file in the root folder then direcotry listing is prevented of the sub-folder as well. And if you place the .htaccess file inside the &#8220;images&#8221; folder then directory listing are prevented of that particular directory only.</p>
<p align="justify">Let&#8217;s suppose that you don&#8217;t want to list &#8220;.jpp , .gif and .zip&#8221;  and you don&#8217;t care about listing other files of that directory then you can out the following code inside .htaccess.</p>
<p><font color="#800000">IndexIgnore *.gif *.jpg *.zip</font></p>
<p align="justify">Finally, If your server is setup with preventing directory listing then you can add the following code in the .htaccess file to allow the directory listing.</p>
<p><font color="#800000">Options +Indexes</font></p>
<p><!--adsense--></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=60&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/03/prevent-directory-listing-htaccess.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Custom Error Page with .htaccess</title>
		<link>http://roshanbh.com.np/2008/02/custom-error-page-htaccess.html</link>
		<comments>http://roshanbh.com.np/2008/02/custom-error-page-htaccess.html#comments</comments>
		<pubDate>Fri, 22 Feb 2008 15:46:13 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[cutom error page]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/02/custom-error-page-htaccess.html</guid>
		<description><![CDATA[In my last post of Hiding .php file extension with .htaccess Michael has mentioned that you can create your own custom page for the the 404(not found) error in server. And alex wanted to know that tip as well.Alex here is the post for you rather than replying your comment. When you mistype the URL [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fcustom-error-page-htaccess.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fcustom-error-page-htaccess.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">In my last post of <a title="hide .php extension with url rewriting" href="http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html">Hiding .php file extension with .htaccess</a> Michael has mentioned that you can create your own custom page for the the 404(not found) error in server. And alex wanted to know that tip as well.Alex here is the post for you rather than replying your comment.</p>
<p><span id="more-50"></span></p>
<p align="justify">When you mistype the URL in a address bar for any website then you usually get the following error with the message.</p>
<h1 style="border: 0px none "><span style="color: #333399;">404 Not Found</span></h1>
<p><span style="color: #333399;">The requested URL /file_name.php does not exist.</span></p>
<p align="justify">Well <span style="color: #333399;">404</span> is error code in http which represents that &#8220;<span style="color: #333399;">file is not found</span>&#8221; in the server.In this article, You&#8217;ll learn the tips to show your own custom error page.</p>
<p align="justify">To display your own custom error page for 404 error code, create a .htaccess file in the root of the web server and place the following code in that file.</p>
<p><strong>ErrorDocument 404 /errror404.htm<br />
</strong></p>
<p align="justify">This would cause any error code resulting in 404 to be forwarded to <span style="color: #333399;">yoursite.com/error404.html</span>.</p>
<p align="justify">In the above line <strong><span style="color: #333399;">ErrorDocument</span></strong> is a server directive and <strong><span style="color: #333399;">404</span></strong> is the server status code and last part is the name of the error page created by yourself.</p>
<p align="justify">This is just a simple example of custom error document of the 404 error. If you want to create the custom error page for the codes 404 and 400 (bad request) then you can put the two following lines in .htaccess file.</p>
<p><strong>ErrorDocument 404 /errror404.htm</strong><br />
<strong>ErrorDocument 400 /errror400.htm</strong></p>
<p align="justify"><strong>Note : </strong>Never try to put a ErrorDocument for code 200 which mean that page is found and causes the infinite loop in the server.</p>
<p>You can see the various http status code in the <a title="custom error page" href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes" target="_blank"><span><span class="a">http://en.wikipedia.org/wiki/List_of_HTTP_status_codes</span></span></a></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=50&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/02/custom-error-page-htaccess.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Hide .php extension with url rewriting using .htaccess</title>
		<link>http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html</link>
		<comments>http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html#comments</comments>
		<pubDate>Wed, 13 Feb 2008 12:12:44 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[file extension]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html</guid>
		<description><![CDATA[Last time I&#8217;ve written an article about hiding php file extension where I&#8217;ve showed you how you can use .html or .asp extension of file instead of .php extension. But there was one flaw in that technique you have had to change the file extension explicitly but in this post I&#8217;m going to show you [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fhide-php-url-rewriting-htaccess.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F02%2Fhide-php-url-rewriting-htaccess.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Last time I&#8217;ve written an article about <a href="http://roshanbh.com.np/2008/01/hiding-php-file-extension.html" title="hide php file extension">hiding php file extension</a> where I&#8217;ve showed you how you can use .html or .asp extension of file instead of .php extension. But there was one flaw in that technique you have had to change the file extension explicitly but in this post I&#8217;m going to show you how to rewrite the URL instead of renaming the file extension  Using this technique you will see <font color="#800080">product.html</font> in the address bar of the browser but the actual file name remains <font color="#800080">product.php</font> and you don&#8217;t need to rename the file extension. Furthermore you can rewrite the URL like <font color="#800080">product.php?id=5</font> to <font color="#800080">product-5.html</font>.</p>
<p><span id="more-44"></span></p>
<h4>what is the benefits of rewriting URL?</h4>
<p align="justify">When a search engine visits the dynamic url like <font color="#800080">product.php?id=5</font> it does not give much importance to that URL as search engine sees <font color="#800080">&#8220;?&#8221;</font> sign treat it as a url which keeps on changing. so we&#8217;re converting the dynamic URL like the <font color="#800080">product.php?id=5</font> to static url format like <font color="#800080">product-5.html</font>. We&#8217;ll rewrite the url in such a way that in browser&#8217;s address bar it will display as a <font color="#993366">product-5.html</font> but it actually calls the file <font color="#993366">product.php?id=5</font>. So that why these kind of URL also named as SEO friendly URL.</p>
<h4>what is required for URL rewriting ??</h4>
<p>To rewrite the URL you must have the <a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html" title="apache's mod_rewrite module" target="_blank">mod_rewrite</a> module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter <font color="#993366">500 Internal Sever Error</font>. If you don&#8217;t know much about mod_rewrite module then please check this post to know <a href="http://roshanbh.com.np/2008/04/check-enable-mod_rewrite-apache.html" title="check and enable mod_rewrite module">how to check and enable mod_rewrite module in apache?</a></p>
<h4>Examples of url rewriting for seo friendly URL</h4>
<p align="justify">For rewriting the URL, you should create a <font color="#993366">.htaccess</font> file in the root folder of your web directory. And have to put the following codes as your requirement.</p>
<p><font color="#800000">Options +FollowSymlinks<br />
RewriteEngine on<br />
RewriteRule ^(.*)\.htm$ $1.php [nc]</font></p>
<p align="justify">The following example will rewrite the  test.php to test.html i.e when a URL like http://localhost/test.htm is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and <font color="#800000">$1</font> represents the first regular expression of the part of the RewriteRule and <font color="#993366">[nc]</font>  means  not case sensitive.</p>
<p><font color="#800000">Options +FollowSymlinks<br />
RewriteEngine on<br />
RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1</font></p>
<p align="justify">The following example will rewrite the  product.php?id=5 to porduct-5.html i.e when a URL like http://localhost/product-5.html calls <font color="#993366">product.php?id=5</font> automatically.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=44&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html/feed</wfw:commentRss>
		<slash:comments>132</slash:comments>
		</item>
		<item>
		<title>Uploading large(big)  files in PHP using .htaccess</title>
		<link>http://roshanbh.com.np/2008/01/uploading-larger-files-in-php.html</link>
		<comments>http://roshanbh.com.np/2008/01/uploading-larger-files-in-php.html#comments</comments>
		<pubDate>Tue, 15 Jan 2008 18:31:20 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[upload large file]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/2008/01/uploading-larger-files-in-php.html</guid>
		<description><![CDATA[I&#8217;ve seen that many of my friends are struggling with the uploads of the bigger or larger files in PHP. After looking at their struggle, i&#8217;m here to solve the problem of uploading larger or bigger files in PHP. Most of the web servers are configured such a way that a user can only upload [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F01%2Fuploading-larger-files-in-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F01%2Fuploading-larger-files-in-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">I&#8217;ve seen that many of my friends are struggling with the uploads of the bigger or larger files in PHP. After looking at their struggle, i&#8217;m here to solve the problem of uploading larger or bigger   files in PHP.</p>
<p align="justify">Most of the web servers are configured such a way that a user can only upload the maximum file size of 2MB. So there might be the problem for the people who wants to upload the .pdf file of size around 15MB. But, you can increse the maximum upload file size limit by using .htaccess file.</p>
<p><span id="more-30"></span></p>
<p align="justify">Here is a small tips for you which you can use to upload such a large file using file field of the form and move_uploaded_file() function in PHP.</p>
<p><strong>1)</strong> Create a .htaccess file in the root folder of web server.</p>
<p><strong>2)</strong> Put the following code in side the .htaccess file and save it.</p>
<blockquote><p>php_value upload_max_filesize 20M<br />
php_value post_max_size 20M<br />
php_value max_execution_time 200<br />
php_value max_input_time 200</p></blockquote>
<p align="justify">Now you can upload the file-size up-to 20MB in a simple way using file field in your html form and move_uploaded_file() function available in PHP. In the above .htaccess file, uploading capability is increased by the four parameter first one is maximum file size for uploading, second one is maximum size of the post data , third one is maximum time in seconds a script is allowed to run before it is terminated by the parser and last one is maximum time in seconds a script is allowed to parse input data such as like file uploads, POST and GET data.</p>
<p>You can change the above parameter to upload the bigger file size than 20MB.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=30&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/01/uploading-larger-files-in-php.html/feed</wfw:commentRss>
		<slash:comments>77</slash:comments>
		</item>
		<item>
		<title>Hiding PHP file extension</title>
		<link>http://roshanbh.com.np/2008/01/hiding-php-file-extension.html</link>
		<comments>http://roshanbh.com.np/2008/01/hiding-php-file-extension.html#comments</comments>
		<pubDate>Tue, 01 Jan 2008 15:01:00 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[file extension]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/hiding-php-file-extension/</guid>
		<description><![CDATA[Do you want to hide your web site&#8217;s server script identity ? If you don&#8217;t want to reveal the programming language ( server side script ) of your website to visitors of website so that any hacker or spammer will not be able to intrude or inject any code in your website. Here is a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F01%2Fhiding-php-file-extension.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F01%2Fhiding-php-file-extension.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify">Do you want to hide your web site&#8217;s server script identity ? If you don&#8217;t want to reveal the programming language ( server side script ) of your website to visitors of website so that any hacker or spammer will not be able to intrude or inject any code in your website.</p>
<p style="text-align: justify">Here is a small technique for you, you can use .html or .asp file to work as a php file i.e. use .asp or .html extension instead of .php. You just need to create a .htaccess file and put the following code in the .htaccess file. Remember that the .htaccess file should be placed in the root folder of your website.</p>
<p><span id="more-23"></span><!--adsense--></p>
<blockquote><p><span style="color: #660000"># Make PHP code look like asp or perl code</span><br />
<span style="color: #660000"> </span><span style="color: #660000">AddType application/x-httpd-php .asp .pl</span></p></blockquote>
<p style="text-align: justify">if you place the the above code in the .htaccess file then you can use contact.asp as the name of the file. Now a visitor thought that it is a ASP file but this file contains the codes of PHP.</p>
<p>You can put the following code in .htaccess file to work .htm or .html file as PHP file.</p>
<blockquote>
<p align="left"><span style="color: #660000"># Make all PHP code look like HTML<br />
</span><span style="color: #660000">AddType application/x-httpd-php .htm .html</span></p></blockquote>
<address> </address>
<address><a rel="nofollow"  href="http://www.testking.com/3M0-600.htm">3M0-600</a> certification exams are very important for IT professional for getting more updated skills. <a rel="nofollow"  href="http://www.testking.com/4H0-028.htm">4H0-028</a>, Hyperion Certified Professional &#8211; System 9 Planning 4.1 exams are very significant exams for becoming more professionals in the field of technology. <a rel="nofollow" href="http://www.testking.com/50-686.htm">50-686</a>, certification exams are very assistive to give full training to IT professionals. <a rel="nofollow" href="http://www.testking.com/640-802.htm">640-802</a> is also known as CCNA, very significant exams for Cisco networking administrators. <a rel="nofollow"  href="http://www.testking.com/640-863.htm">640-863</a> certification exams provide very exact solutions of Cisco networking in the most effective manner. 3Com Certified IP Telephony NBX Expert Final Exam V3.0 is also known as <a rel="nofollow"  href="http://www.testking.com/3M0-701.htm">3M0-701</a> which provides authentic knowledge for operating IP telephony networks. <a rel="nofollow" href="http://www.testking.com/310-203.htm">310-203</a>, Sun Certified System Administrator for the Solaris 10 Operating System is designed to improve the professional talents of the individuals for operating system efficiently.<br />
</address>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=23&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/01/hiding-php-file-extension.html/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>301 redirect in PHP and .htaccess</title>
		<link>http://roshanbh.com.np/2007/12/301-redirect-in-php-and-htaccess.html</link>
		<comments>http://roshanbh.com.np/2007/12/301-redirect-in-php-and-htaccess.html#comments</comments>
		<pubDate>Sat, 29 Dec 2007 17:12:00 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/301-redirect-in-php-and-htaccess/</guid>
		<description><![CDATA[What is 301 redirect ? You have a website and its all pages are ranked in the search engine. And now you&#8217;ve moved these files to a new domain. What will happen in this scenario!!. You are sending the visitor to &#8220;Error 404 &#8211; File not found&#8221; page when they follow your website in the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2007%2F12%2F301-redirect-in-php-and-htaccess.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2007%2F12%2F301-redirect-in-php-and-htaccess.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><span style="font-weight: bold">What is 301 redirect ?</span></p>
<p style="text-align: justify">You have a website and its all pages are ranked in the search engine. And now you&#8217;ve moved these files to a new domain. What will happen in this scenario!!. You are sending the visitor to &#8220;Error 404 &#8211; File not found&#8221; page when they follow your website in the search engine.  Furthermore, if you place the  custom error page, then also you will be   keep loosing ranking in upcoming days in search engines as the original file could not be found in the old URL.  So what is the solution for this?? The solution is 301 redirect which means moved permanently. It is is the most efficient and search engine as well as visitor friendly method for  the webpage redirection.</p>
<p><span id="more-21"></span><br />
<span style="font-weight: bold">Why do you need 301 redirect ?</span></p>
<p style="text-align: justify">Have you ever typed yahoo.com in your browser, what happens next is it will redirect you to www.yahoo.com, its all the result of the 301 redirect. so, why do you need to do so?. If you&#8217;re not doing so, then you&#8217;re splitting yourself to two different URL and search engine spiders can also crawls your site&#8217;s content by two different URL which may result to &#8220;duplicate content&#8221; penalty by search engines if search engines collect two copies of the same data from two different URLs.</p>
<p><span style="font-weight: bold">How to do 301 redirect in PHP ?</span></p>
<p style="text-align: justify">If you want to redirect a single page to another location then put the following code in the old page which have been moved.</p>
<pre style="overflow: auto"><font color="#800000">&lt;?php
 header('HTTP/1.1 301 Moved Permanently');
 header('Location: http://www.new-domain.com/new-file-name.php');
?&gt;</font></pre>
<p>If you want to redirect non-www to www domain name then put the following code into top of every page of the website</p>
<pre style="overflow: auto"><font color="#800000">&lt;?php
if (substr(getenv('HTTP_HOST'),0,3) != 'www')
{
  header('HTTP/1.1 301 Moved Permanently');
  header('Location:http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
?&gt;</font></pre>
<p><span style="font-weight: bold">How to do 301 redirect in .htaccess file?</span></p>
<p style="text-align: justify">Put the following code into the .htaccess file and upload it into the root folder of the website. Note that this file only works for the website which is running under Apache Web Server.</p>
<pre class="php" style="overflow: auto"><font color="#800000">RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]</font></pre>
<p style="font-size: 13px">&nbsp;</p>
<p><!--wsa:post-google-ads--></p>
<address> The significance of <a href="http://www.actual-exams.com/MCDBA-practice-exam.htm" rel="nofollow">mcdba certification</a> is acknowledged by the data base administrators. The administrators of networks may earn great prominence by getting <a href="http://www.actual-exams.com/N-plus-practice-exam.htm" rel="nofollow">network+</a> certification. There are different online institutes which offer their service for the exclusive <a href="http://www.actual-exams.com/MCSA-practice-exam.htm" rel="nofollow">mcsa training</a> with %100 guarantee of success. The administrators and system analysts are provided with the special <a href="http://www.actual-exams.com/MCP-practice-exam.htm" rel="nofollow">mcp training</a> for becoming IT professionals. The <a href="http://www.actual-exams.com/Security-Plus-Certification-practice-exam.htm" rel="nofollow">security training</a> helps the networking administrators and engineers to use all such protective measures against any hacking attacks. All kinds of information are provided for the individuals who want to get <a href="http://www.actual-exams.com/Cisco-practice-exam.htm" rel="nofollow">cisco training</a> via online sources. For the preparation of different kinds of exams, <a href="http://www.actual-exams.com/Microsoft-practice-exam.htm" rel="nofollow">microsoft training</a> is provided for the candidates. </address>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=21&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2007/12/301-redirect-in-php-and-htaccess.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/40 queries in 0.062 seconds using disk: basic
Object Caching 1533/1617 objects using disk: basic

Served from: roshanbh.com.np @ 2012-05-21 20:16:30 -->
