<?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>Dream House &#187; htaccess</title>
	<atom:link href="http://sajjadhossain.com/tag/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://sajjadhossain.com</link>
	<description>Courage to do something...</description>
	<lastBuildDate>Wed, 18 Aug 2010 17:39:32 +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>301 (Permanent) redirection using .htaccess file</title>
		<link>http://sajjadhossain.com/2010/03/10/301-permanent-redirection-using-htaccess-file/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://sajjadhossain.com/2010/03/10/301-permanent-redirection-using-htaccess-file/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 05:55:23 +0000</pubDate>
		<dc:creator>Mohammad Sajjad Hossain</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://sajjadhossain.com/?p=229</guid>
		<description><![CDATA[A few days back one of my project&#8217;s domain changed. The nature of this project was such that it provides URLs to it&#8217;s subscribers to use in their site for different purposes. As it has a huge user base, it was quite impossible to change the URLs already provided to the subscribers. That&#8217;s why I [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://sajjadhossain.com/wp-content/uploads/2010/03/301_htaccess_redirect.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img class="alignleft size-full wp-image-234" title="301_htaccess_redirect" src="http://sajjadhossain.com/wp-content/uploads/2010/03/301_htaccess_redirect.png" alt="301 redirection with .htaccess" width="220" height="300" /></a>A few days back one of my project&#8217;s domain changed. The nature of this project was such that it provides URLs to it&#8217;s subscribers to use in their site for different purposes. As it has a huge user base, it was quite impossible to change the URLs already provided to the subscribers. That&#8217;s why I searched for a solution which will redirect the subscribers to new domain. I knew HTACCESS files can provide this type of service. So, I searched web for a solution to this problem &#8211; 301 redirection with HTACCESS file. Then I found the following solution. Before I provide the solution, I just want to say I am not an expert of HTACCESS <img src='http://sajjadhossain.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="301 (Permanent) redirection using .htaccess file" />  .</p>
<p>I have created .htaccess file with the following line to redirect any request to http://www.oldurl.com/ to https://www.newurl.com/.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">redirect 301 / https://www.newurl.com/</pre></div></div>

<p>The line stated above tells Apache server to redirect all request to http://www.oldurl.com/ will be redirected to https://www.newurl.com/using 301 permanent redirection. It worked fine.</p>
<p>After implementing the solution I faced another problem. The line of code was redirecting to only HTTPS irrespective of the request made to HTTP or HTTPS. This caused a problem for the pages which were non-secured, I mean shown via HTTP. These pages contain elements like CSS, JavaScript files, images etc. which are linked as HTTP. So, browsers started generating security warnings. Again I took help of Google and searched for a solution. After studying different problems I wrote the following lines of code in the .htaccess file and it worked.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ https://www.newurl.com/$1 [L,R=301]
RewriteCond %{HTTPS} !^443
RewriteRule ^(.*)$ http://www.newurl.com/$1 [L,R=301]</pre></div></div>

<p>The above code does a conditional redirection. If the request is made to HTTP then it redirects to HTTP and the same is for HTTPS.</p>
<p>FYI, my project is built with CodeIgniter and the redirection worked fine with it.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://sajjadhossain.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://sajjadhossain.com/2010/03/10/301-permanent-redirection-using-htaccess-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
