<?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>webdirect.no &#187; htaccess</title>
	<atom:link href="http://webdirect.no/tag/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://webdirect.no</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jan 2009 20:26:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Use WordPress as CRM system</title>
		<link>http://webdirect.no/web/use-wordpress-as-crm-system/</link>
		<comments>http://webdirect.no/web/use-wordpress-as-crm-system/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 14:14:54 +0000</pubDate>
		<dc:creator>Morten Jacobsen</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://localhost/project/webdirect2/web/use-wordpress-as-crm-system/</guid>
		<description><![CDATA[Background I have been looking for a clean and simple CRM solution for my web site for some time. I use this web site more like a sketch block where I ramble down some of my findings and howto&#8217;s mainly for my self. To simplify this process, I wanted to convert my old, file based [...]]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>I have been looking for a clean and simple CRM solution for my web site for some time. I use this web site more like a sketch block where I ramble down some of my findings and howto&#8217;s mainly for my self. To simplify this process, I wanted to convert my old, file based PHP-site to something a bit more dynamic and easily maintainable. I didn&#8217;t do a deep analysis of what&#8217;s available, but I quickly browsed through some alternatives (<a href="http://drupal.org/">Drupal</a>, <a href="http://expressionengine.com/">Expression Engine</a>, <a href="http://www.movabletype.com/">Movable Type</a> and <a href="http://wordpress.org">WordPress</a>). To make a long story short; I went for <b>WordPress</b> because of earlier experience with this tool.</p>
<p>It was quite easy to cut&#8217;n paste all my content into its &#8220;pages&#8221; system. The problem arised when I needed to figure out how i could redirect all my .html and .php filenames to folder names that all new systems base their URL structure on. </p>
<p><a href="http://www.flickr.com/photos/84892169@N00/1043966166/" title="" target="_blank"><img src="http://farm2.static.flickr.com/1051/1043966166_b895be3c34.jpg" alt="" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://localhost/project/webdirect2/wp-content/plugins/photo_dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/84892169@N00/1043966166/" title="MR+G" target="_blank">MR+G</a></small></p>
<p>Most of the content are from 2000-2003 and all of it are comprehensively crawled by Google and linked up by others. So breaking those links was not an option. Hacking WordPress to make it possible to use .php and .html endings was not either to smart, both because it was too time consuming and also that I didn&#8217;t wanted to alter WordPress and make it harder  for me to future upgrades.</p>
<h3>Solution: Rewrite-rules in .htaccess files</h3>
<p>And that&#8217;s really why I wrote this article &#8211; it wasn&#8217;t too much information about this on the web. This is what I wanted to do:</p>
<p>Permantent redirect (301) <code>/linux/mutt.php</code> to <code>/linux/mutt/</code><br />
and remove all index.php so <code>/linux/index.php</code> becomes <code>/linux/</code></p>
<h3>My .htaccess file</h3>
<pre>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Removes index.php-pages
RewriteCond %{THE_REQUEST} \/index\.php(.*)\ HTTP/ [NC]
RewriteRule ^([^.]*)index\.php(.*)$ http://webdirect.no/$1 [R=301,L]

# Externally redirect direct client requests for .php files to non-.php URLs
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/){1,10}[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://webdirect.no/$1 [R=301,L] 

# Externally redirect direct client requests for .php files to non-.php URLs
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/){1,10}[^.]+\.html(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.html$ http://webdirect.no/$1 [R=301,L]

# standard wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</pre>
<h3>Rewrite rules explained</h3>
<pre>
# Removes index.php-pages
RewriteCond %{THE_REQUEST} \/index\.php(.*)\ HTTP/ [NC]
RewriteRule ^([^.]*)index\.php(.*)$ http://webdirect.no/$1 [R=301,L]
</pre>
<p>This one just removes all /index.php from requests and creates a permanent redirect (HTTP 301) so crawles can detect that this page has moved to a new URL</p>
<pre>
# Externally redirect direct client requests for .php files to non-.php URLs
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/){1,10}[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://webdirect.no/$1 [R=301,L]
</pre>
<p>Removes .php extensions if the depth of the URL strucure are between 3 and 10 slashes. This to allow some root files to have .php ending, like /login.php for example.</p>
<h3>So, what about .php files from WordPress?</h3>
<p>Yes, that&#8217;s right. WordPress uses .php-extention on many internal files that&#8217;s crucial to make the dog fly, and since rewrite-rules in .htaccess files are inhereted, we have to turn off rewriting in some folders (/wp-admin).</p>
<p>This .htaccess file turns of all rewrite rules so WordPress can function like it&#8217;s meant to in this folder.</p>
<h3>.htaccess file inside /wp-admin</h3>
<pre>
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine Off
&lt;/IfModule&gt;
</pre>
<p>As always, if you know a smarter way to do this, leave a comment, please!</p>
]]></content:encoded>
			<wfw:commentRss>http://webdirect.no/web/use-wordpress-as-crm-system/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

