<?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>A K Chauhan's Blog &#187; Apache</title>
	<atom:link href="http://www.akchauhan.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akchauhan.com</link>
	<description>PHP, MySql, JavaScript, JQuery, Prototype, Drupal, HTML, CSS and more...</description>
	<lastBuildDate>Mon, 02 Jan 2012 03:29:10 +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>Create Virtual Hosts and run multiple websites on Amazon server</title>
		<link>http://www.akchauhan.com/create-virtual-hosts-and-run-multiple-websites-on-amazon-server/</link>
		<comments>http://www.akchauhan.com/create-virtual-hosts-and-run-multiple-websites-on-amazon-server/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 07:42:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[Vistual Host]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=525</guid>
		<description><![CDATA[You can create virtual hosts on any Linux or window platform if you are using Apache web server. Virtual hosts or v-hosts is basically Apache feature. I&#8217;m considering here Amazon server running with Apache version 2 or above. So, basically for creating v-hosts you need to modify Apache&#8217;s configuration (httpd.conf) file. You need the root [...]]]></description>
			<content:encoded><![CDATA[<p>You can create <strong>virtual hosts</strong> on any Linux or window platform if you are using <strong>Apache web server</strong>. Virtual hosts or v-hosts is basically Apache feature. I&#8217;m considering here Amazon server running with Apache version 2 or above. So, basically for creating v-hosts you need to modify Apache&#8217;s configuration (<strong>httpd.conf</strong>) file. You need the root access for all this modifications. Here I&#8217;m showing how we create the &#8220;<strong>name-based virtual hosting</strong>&#8220;. This is the easiest way of creating virtual host.<br />
On Amazon server httpd.conf is located on &#8216;<strong>/etc/httpd/conf/httpd.conf</strong>&#8216; location. You need to follow these steps:-<br/><br />
<strong>1. First, take the backup of this file so in case if anything goes wrong you can rollback changes.</strong><br />
<strong>2. Download this file in your local machine and open it in any text editor.</strong><br />
<strong>3. Go to section 3 (Virtual Hosts)  of this document.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">### Section 3: Virtual Hosts</pre></div></div>

<p><strong>4. Un-comment this line</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">NameVirtualHost *:80</pre></div></div>

<p><strong>5. Now create v-hosts like this</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;VirtualHost *:<span style="color: #cc66cc;">80</span>&gt;</span>
    ServerAdmin admin@mydomain1.com
    DocumentRoot /var/www/html/domainname1
    ServerName www.domainname1.com
    ErrorLog logs/www.domainname1.com-error_log
    CustomLog logs/www.domainname1.com-access_log common
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>VirtualHost&gt;</span>
<span style="color: #009900;">&lt;VirtualHost *:<span style="color: #cc66cc;">80</span>&gt;</span>
    ServerAdmin admin@mydomain2.com
    DocumentRoot /var/www/html/domainname2
    ServerName www.domainname2.com
    ErrorLog logs/www.domainname2.com-error_log
    CustomLog logs/www.domainname2.com-access_log common
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>VirtualHost&gt;</span></pre></div></div>

<p>Here we have create two virtual host one <strong>www.domainname1.com</strong> and second one <strong>www.domainname2.com</strong>. <strong>We have specified 5 Apache directive into a VirtualHost container.</strong> We can put almost any Apache directive into a VirtualHost container. Let&#8217;s discuss each one by one.<br/><br />
<strong>ServerAdmin</strong> &#8211; Here we specified email address of server administrator. If there is any issue Apache show this email address for contact.<br />
<strong>DocumentRoot </strong> &#8211; Here we give the absolute path of directory where our website files are located.<br />
<strong>ServerName </strong> &#8211; Here we give the name of our domain which is pointed to &#8220;/var/www/html/domainname1&#8243; directory.<br />
<strong>ErrorLog</strong> &#8211; Absolute path of Error log file for this domain.<br />
<strong>CustomLog</strong> &#8211; Absolute path of custom log file for this domain.<br/></p>
<p><strong>6. Restart the Apache web server to apply these changes.</strong><br />
You can restart your Apache server using Terminal or Putty on Windows.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">service httpd restart</pre></div></div>

<p><strong>Note:-</strong> One more thing which you need to do is you need to point both the domains &#8220;www.domainname1.com&#8221; and &#8220;www.domainname2.com&#8221; to the IP address of the Amazon server. </p>
<p>The Apache server it self find out the domain name form <strong>request header</strong> and point the incoming request to correct &#8220;<strong>DocumentRoot</strong>&#8221; directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-virtual-hosts-and-run-multiple-websites-on-amazon-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create Search Engine Friendly(SEF) websites in PHP using URL rewriting</title>
		<link>http://www.akchauhan.com/create-search-engine-friendlysef-websites-in-php-using-url-rewriting/</link>
		<comments>http://www.akchauhan.com/create-search-engine-friendlysef-websites-in-php-using-url-rewriting/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 17:40:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[SEF]]></category>
		<category><![CDATA[url rewriting]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=196</guid>
		<description><![CDATA[This article is for beginners who want to learn how to create search engine friendly(SEF) URLs (or Clean URLs) for a website. I am considering that you are using Apache web server. For clean URLs we need to do URL rewriting. Note:- The “mod_rewrite” module should be enabled in Apache httpd.conf file. We can define [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_206" class="wp-caption aligncenter" style="width: 384px"><img src="http://www.akchauhan.com/wp-content/uploads/2009/04/sef-url.jpg" alt="Search Engine Friendly URL" title="Search Engine Friendly URL" width="374" height="34" class="size-full wp-image-206" /><p class="wp-caption-text">Search Engine Friendly URL</p></div>
<p>This article is for beginners who want to learn how to create search engine friendly(SEF) URLs (or Clean URLs) for a website. I am considering that you are using Apache web server. For clean URLs we need to do URL rewriting. </p>
<p><strong>Note:- The “mod_rewrite” module should be enabled in Apache httpd.conf file.</strong></p>
<p>We can define our rewrite conditions and rewrite rules in httpd.conf file but on shared hosting we don&#8217;t have access to this configuration file. So, In that case we can define these conditions and rules in &#8216;.htaccess&#8217; file.</p>
<p><strong>&#8216;.htaccess&#8217; file provide configuration settings on per-directory basic</strong>. You need to place this .htaccess file in your server’s root directory.</p>
<p>We need to put the following code in our .htaccess file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>IfModule mod_rewrite<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
  RewriteEngine on
&nbsp;
  <span style="color: #666666; font-style: italic;"># Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
</span>  RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>f
  RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>d
  RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$ index<span style="color: #339933;">.</span>php?q<span style="color: #339933;">=</span>$<span style="color:#800080;">1</span> <span style="color: #009900;">&#91;</span>L<span style="color: #339933;">,</span>QSA<span style="color: #009900;">&#93;</span>
<span style="color: #339933;">&lt;/</span>IfModule<span style="color: #339933;">&gt;</span></pre></div></div>

<p>First, we are checking &#8216;mod_rewrite&#8217; module is available and loaded by Apache web server. If this module is loaded then only our rewrite rule work.</p>
<p>Then we need to &#8216;ON&#8217; RewriteEngine.  </p>
<p>In rewrite conditions we are checking few things. Like in</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>f</pre></div></div>

<p>we are checking the given file/path is not a file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!-</span>d</pre></div></div>

<p>we are checking the given file/path is not a directory. </p>
<p>If the above two conditions satisfy than only our rewrite rule apply to the given URL. We are doing this because if browser request any resource like JavaScript or CSS or Image files than we don&#8217;t want to rewrite those URLs. If any path/URL which does not exist on our server will be rewrite by RewriteRule. All such type of requests will be handled by index.php file.</p>
<p>For example, If we write<br />
<strong><br />
http://www.websitename.com/article/25</strong> (This URL is not exist on our server)</p>
<p>in address bar then this URL is rewritten as </p>
<p><strong>http://www.websitename.com/index.php?q=article/25</strong></p>
<p>Now, the only thing we need to do is to handle all the requests properly in our index.php file. We can create a file &#8216;url.inc&#8217; for handling all the conditions and include it in top of our index.php file.</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: #666666; font-style: italic;">/*url.inc file*/</span>
&nbsp;
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'article'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> isnumeric<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'article.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>some other condition<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// include some other file</span>
	<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If any of the condition mentioned in the &#8216;url.inc&#8217; file not match then index.php files content will execute.</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: #666666; font-style: italic;">/*index.php file*/</span>
&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;This is the index.php file.&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-search-engine-friendlysef-websites-in-php-using-url-rewriting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How redirect users to access your website with &#8216;www.&#8217; prefix</title>
		<link>http://www.akchauhan.com/how-redirect-users-to-access-your-website-with-www-prefix/</link>
		<comments>http://www.akchauhan.com/how-redirect-users-to-access-your-website-with-www-prefix/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 10:31:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[url rewriting]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=192</guid>
		<description><![CDATA[Normally your website is accessible both with and without &#8216;www.&#8217; prefix. And if you want your users to redirect to &#8216;www.&#8217; prefix when they access your website without &#8216;www.&#8217; prefix. You can do that using &#8216;.htaccess&#8217; file. We use .htaccess file to make configuration changes on per-directory basic. You need to place this .htaccess file [...]]]></description>
			<content:encoded><![CDATA[<p>Normally your website is accessible both with and without &#8216;www.&#8217; prefix. And if you want your users to redirect to &#8216;www.&#8217; prefix when they access your website without &#8216;www.&#8217; prefix. You can do that using &#8216;.htaccess&#8217; file.</p>
<p>We use .htaccess file to make configuration changes on per-directory basic. You need to place this .htaccess file in your server&#8217;s root directory. </p>
<p>Basically, we need to write some rewrite rules for our URL in this file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>IfModule mod_rewrite<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
      RewriteEngine on
      RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_HOST<span style="color: #009900;">&#125;</span> ^yourwebsite<span style="color: #339933;">.</span>com$ <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
      RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.yourwebsite.com/$1 [L,R=301]</span>
<span style="color: #339933;">&lt;/</span>IfModule<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Reverse of this is also possible. If we want to redirect all website users to access the website without the &#8216;www.&#8217; prefix. Then we need to write the following rewrite rules in out .htaccess file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>IfModule mod_rewrite<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
      RewriteEngine on
      RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_HOST<span style="color: #009900;">&#125;</span> ^www<span style="color: #339933;">.</span>yourwebsite<span style="color: #339933;">.</span>com$ <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
      RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//yourwebsite.com/$1 [L,R=301]</span>
<span style="color: #339933;">&lt;/</span>IfModule<span style="color: #339933;">&gt;</span></pre></div></div>

<p><strong>Note:-</strong> The &#8220;mod_rewrite&#8221; module should be enabled in Apache httpd.conf file. Otherwise URL rewriting will not work. For enabling this module you need to remove &#8216;#&#8217; before </p>
<p><strong>LoadModule rewrite_module modules/mod_rewrite.so</strong></p>
<p>line in your httpd.conf file. We are also checking in our .htaccess file that the mod_rewrite module is enabled or not. You should also restart your Apache server to apply these changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/how-redirect-users-to-access-your-website-with-www-prefix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

