<?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>Simone Carletti&#039;s Blog &#187; redirects</title>
	<atom:link href="http://www.simonecarletti.com/blog/tags/redirects/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simonecarletti.com/blog</link>
	<description>Simone Carletti&#039;s personal ramblings on programming, syndication, search engines &#38; marketing.</description>
	<lastBuildDate>Tue, 07 Feb 2012 08:48:33 +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>Redmine 0.9.0 and duplicate content issue</title>
		<link>http://www.simonecarletti.com/blog/2009/12/redmine-0-9-0-and-duplicate-content-issue/</link>
		<comments>http://www.simonecarletti.com/blog/2009/12/redmine-0-9-0-and-duplicate-content-issue/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 22:11:31 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Server / Apache]]></category>
		<category><![CDATA[Softwares]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[redirects]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=886</guid>
		<description><![CDATA[Redmine 0.9.0 duplicates the most part of application URLs: here's an Apache configuration file to redirect the old URLs to the new ones.]]></description>
			<content:encoded><![CDATA[<p>A couple of hours ago I upgraded the <a href="http://code.simonecarletti.com/">code domain</a> from Redmine 0.8.0 to Redmine 0.9.0, currently available in pre-beta.</p>
<p>Redmine 0.9.0 offers tons of improvements but one among all forced my decision to upgrade without waiting for a final release: <strong>Rails 2.3.5</strong>. Redmine 0.8.x is built on Rails 2.1.0 and there seems to be some kind of weird Rails-Redmine-Passenger-Ruby EE memory leaks.</p>
<p>With the new release, Redmine <a title="Redmine - Patch #1901: RESTful URLs for everything - Redmine" href="http://www.redmine.org/issues/1901">has changed</a> the most part of its URLs. The development team basically migrated all routes to a more RESTful-oriented architecture. They did a wonderful job, unfortunately they probably chose the worst way to ensure backward-compatibility: <strong>duplication</strong>.</p>
<p>All the old routes are still available along with the new ones and this can cause several duplicate content issues. To patch the problem, I configured some Apache redirection rules in order to permanently redirect the old URLs to the new ones.<span id="more-886"></span></p>
<p><script src="http://gist.github.com/265300.js?file=redmine-080-to-090.conf"></script></p>
<p>The gist doesn&#8217;t pretend to solve all issues. It&#8217;s just a quick and (quite) dirty fix.</p>
<p>From Redmine side, I would have setup a <a title="Riding Rails: Introducing Rails Metal" href="http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal">Rails Metal</a> to redirect all the old URLs to the new ones. This is not as efficient as relying on the web server, but this is compatible with any user environment.</p>
<p>Feel free to fork, clone and update the gist. After all, <strong>this is a Git repository</strong>!</p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/07/configuring-git-repository-with-redmine/' rel='bookmark' title='Configuring a Git repository with Redmine'>Configuring a Git repository with Redmine</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/' rel='bookmark' title='Apache .htaccess query string redirects'>Apache .htaccess query string redirects</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/' rel='bookmark' title='Generic Apache configuration snippets'>Generic Apache configuration snippets</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/12/redmine-0-9-0-and-duplicate-content-issue/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache .htaccess query string redirects</title>
		<link>http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/</link>
		<comments>http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 23:16:47 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Server / Apache]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[redirects]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=87</guid>
		<description><![CDATA[How to configure a query string based redirect for a specific page using Apache and .htaccess.]]></description>
			<content:encoded><![CDATA[<p>One of the most common question when talking about Apache and mass-redirections, is <strong>how to configure a query string based redirect for a specific page</strong>. Creating a <strong>single page redirect</strong> in Apache is as simple as writing the following line in your .htaccess file.</p>
<div class="codecolorer-container text default brush: text;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Redirect /page.php http://mydomain.site/destination.php</div></td></tr></tbody></table></div>
<p>If you need to <strong>mass-redirect a group of pages</strong> you would probably need to use the <code>RedirectMatch</code> directive.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RedirectMatch ^/oldfolder/(.*)$ http://mydomain.site/newfolder/$1</div></td></tr></tbody></table></div>
<p>This will redirect any page from the <code>oldfolder</code> to the corresponding one in <code>newfolder</code> with a convenient <strong>one-by-one redirect</strong>.</p>
<p><span id="more-87"></span>Unfortunately, either <code>Redirect</code> nor <code>RedirectMatch</code> allow you to specify a query string for the redirect source. It other words, the following statements are invalid and they will simply be ignored.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Redirect /page.php?id=3 &nbsp;http://mydomain.site/page/3<br />
Redirect /page.php?id=4 &nbsp;http://mydomain.site/page/4<br />
<br />
RedirectMatch ^/page.php?id=([0-9]*)$ &nbsp;http://mydomain.site/page/$1</div></td></tr></tbody></table></div>
<p>The solution requires to change the focus from <a title="mod_alias - Apache HTTP Server" href="http://httpd.apache.org/docs/2.0/mod/mod_alias.html">mod_alias</a> to <a title="mod_rewrite - Apache HTTP Server" href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">mod_rewrite</a>. Here&#8217;s an example.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteEngine On<br />
RewriteCond %{REQUEST_URI} &nbsp;^/page\.php$<br />
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$<br />
RewriteRule ^(.*)$ http://mydomain.site/page/%1.pdf [R=302,L]</div></td></tr></tbody></table></div>
<p>Let me explain the solution for those who wants to learn and not only to copy.</p>
<p>The first line enables the <code>RewriteEngine</code> module. Please note that <code>mod_rewrite</code> Apache module must be installed and enabled in order to use the <code>RewriteEngine</code>.</p>
<p>The <code>RewriteCond</code> statements set all the rewrite conditions. The forth line, the real rewrite directive, will be executed <strong>if and only if all conditions are satisfied by the current request</strong>.</p>
<p>First I want to check the request is for the page I need to redirect. Skipping this condition might cause some unexpected behavior if other pages in my website are using the <code>id</code> parameter. Then I want to base the rewrite rule on the value for the current request query string. Be sure to <strong>wrap the <code>id</code> value within a regular expression match</strong> to be able to reuse the match later as a back-reference.</p>
<p>Finally I can write my redirection rule. This line looks like a <code>RedirectMatch</code> statement. First I specify the pattern for the redirection source, then the redirection target. As you can see, the value for the <code>id</code> parameter captured by the last <code>RewriteCond</code> is referenced in the target with the <code>%N</code> keyword.</p>
<p>The comma separated values at the end of the <code>RewriteRule</code> line define which flags should be applied for this rule. I want to setup a 302 Redirection and be sure Apache won&#8217;t execute any other rule after this one.</p>
<p>PS. If you suffer from &#8220;write-as-less-as-possible&#8221; sickness you might want to change the original rewrite statement with</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteEngine On<br />
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$<br />
RewriteRule ^page\.php$ http://mydomain.site/page/%1.pdf [R=302,L]</div></td></tr></tbody></table></div>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/' rel='bookmark' title='Apache RewriteRule and query string'>Apache RewriteRule and query string</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/' rel='bookmark' title='Generic Apache configuration snippets'>Generic Apache configuration snippets</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/' rel='bookmark' title='Apache Log Regex: a lightweight Ruby Apache log parser'>Apache Log Regex: a lightweight Ruby Apache log parser</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

