<?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>alecs &#187; htaccess</title>
	<atom:link href="http://www.ylipsis.com/blog/tag/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ylipsis.com/blog</link>
	<description>web development, SEO, technology</description>
	<lastBuildDate>Sat, 15 May 2010 11:51:13 +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>htaccess redirecting basics</title>
		<link>http://www.ylipsis.com/blog/2008/09/htaccess-redirecting-basics/</link>
		<comments>http://www.ylipsis.com/blog/2008/09/htaccess-redirecting-basics/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 19:16:01 +0000</pubDate>
		<dc:creator>alecs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.ylipsis.com/blog/?p=87</guid>
		<description><![CDATA[This is going to be a guide for begginers, so don&#8217;t take it personal if I go into dumb details. I am assuming that you have a basic LAMP configuration (Linux, Apache, MySQL, PHP) with a web administration interface such as cPanel. All the following scenarios will require you to edit the .htaccess file in [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-91" title="redirecting" src="http://www.ylipsis.com/blog/wp-content/uploads/2008/09/redirecting.jpg" alt="" width="200" height="110" />This is going to be a guide for begginers, so don&#8217;t take it personal if I go into dumb details. I am assuming that you have a basic LAMP configuration (Linux, Apache, MySQL, PHP) with a web administration interface such as cPanel.</p>
<p>All the following scenarios will require you to edit the <strong>.htaccess</strong> file in your root directory. Htaccess is an optional configuration file used by Apache to handle all incoming requests. You will also need support for mod_rewrite.<span id="more-87"></span></p>
<h2>Redirecting example.com to www.example.com</h2>
<p>The reason for doing this is because, by default, you will have 2 distinct URLs for each page on your website. For example http://www.example.com/download/games.html and http://example.com/download/games.html are one and the same page. Unfortunately search engines assume that they are completely distinct. Some say this will trigger the so-called duplicated content filter or that pagerank may spread across too many pages.</p>
<p>The solution is to redirect one url to the other with the response code 301. I will just use the non-www to www redirection in this article. You need a rule that will be applyable to all the URLs on your website.</p>
<pre>RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]</pre>
<p>This code will find all requests that contain the host <strong>example.com</strong> and redirect them using a 301 code to <strong>www.example.com</strong>. The best part is that any string after the host is taken care of. In other words, http://example.com/<strong>page1.html</strong> will be redirected to http://www.example.com/<strong>page1.html</strong>.</p>
<h2>Redirecting a subfolder to the subdomain</h2>
<p>When you add a new subdomain in cPanel, a folder with the same name is created in your root directory. This is where all the files directly accessible from the subdomain are located. The downside is that you now have 2 ways of viewing the same file: http://www.example.com/<strong>subdomain</strong>/page.html and http://<strong>subdomain</strong>.example.com/page.html. This is not as crucial as the scenario previously discussed because the chances of someone linking to your &#8220;subdomain&#8221; folder are pretty slim. However, we are really into eliminating every duplicated URL out there so we will deal with this problem too :).</p>
<pre>RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/subdomain(.*)$ [NC]
RewriteRule ^subdomain/(.*)$ http://subdomain.example.com/$1 [L,R=301]</pre>
<p>Having these lines in .htaccess will make sure that http://www.example.com/subdomain/page.html will redirect to http://subdomain.example.com/page.html. But we still have http://example.com/subdomain/page.html which is not redirected. So what now?</p>
<h2>Combine them both!</h2>
<pre>RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/subdomain(.*)$ [NC]
RewriteRule ^subdomain/(.*)$ http://subdomain.example.com/$1 [L,R=301]</pre>
<p>You are now fully covered!</p>
<ul>
<li><strong>http://example.com</strong> redirects to <strong>http://www.example.com</strong></li>
<li><strong>http://example.com/somepage.html</strong> redirects to <strong>http://www.example.com/somepage.html</strong></li>
<li><strong>http://www.example.com/subdomain/</strong> redirects to <strong>http://subdomain.example.com/</strong></li>
<li><strong>http://www.example.com/subdomain/somepage.html</strong> redirects to <strong>http://subdomain.example.com/somepage.html</strong></li>
<li><strong>http://example.com/subdomain/somepage.html</strong> redirects to <strong>http://www.example.com/subdomain/somepage.html</strong> which redirects to <strong>http://subdomain.example.com/somepage.html</strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ylipsis.com/blog/2008/09/htaccess-redirecting-basics/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
