<?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>Petra Link Factory &#187; seo url</title>
	<atom:link href="http://www.petralinkfactory.com/tag/seo-url/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.petralinkfactory.com</link>
	<description>Programar no es un hobby es una pasión</description>
	<lastBuildDate>Sun, 15 Jan 2012 09:14:58 +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>URL Amigables (II)(php)</title>
		<link>http://www.petralinkfactory.com/2008/07/15/url-amigables-iiphp/</link>
		<comments>http://www.petralinkfactory.com/2008/07/15/url-amigables-iiphp/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 10:46:10 +0000</pubDate>
		<dc:creator>Valde</dc:creator>
				<category><![CDATA[programación]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[seo url]]></category>
		<category><![CDATA[url amigables]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.petralinkfactory.com/?p=7</guid>
		<description><![CDATA[Bueno con mÃ¡s de dos meses de retardo, voy a seguir con esta serie de artÃ­culos que tienen que ver con las URLs Amigables (en inglÃ©s SEO URLs). La razÃ³n ha sido que he estado trabajando a destajo para un &#8230; <a href="http://www.petralinkfactory.com/2008/07/15/url-amigables-iiphp/">Sigue leyendo <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Bueno con mÃ¡s de dos meses de retardo, voy a seguir con esta serie de artÃ­culos que tienen que ver con las URLs Amigables (en inglÃ©s SEO URLs). La razÃ³n ha sido que he estado trabajando a destajo para un proyecto en el que estoy trabajando, en el que estoy aprendiendo mucho y ya irÃ© publicando las cosas que he ido aprendiendo.</p>
<p>Bueno vamos a lio con las URL Amigables.</p>
<p>Lo primero he de decir que dependiendo de si trabajamos en IIS o en Apache, en los ejemplos irÃ© mostrandolo.</p>
<p>En primer lugar decir que las pruebas las he desarrollado sobre Windows Vista Home Premium con el Servidor Web WampServer 2.0, aunque luego lo he probado en un Windows 2003 Server con IIS 6 y en Debian Linux con Apache 2.0 (en mi hosting de Powweb).</p>
<p>Si estamos en Apache lo primero que tenemos que hacer es crear un fichero <em><strong>.htaccess</strong></em> para poder redirigir las urls amigables a las pÃ¡ginas que corresponden, para ello recordamos que el artÃ­culo I se dice que vamos a utilizar esta pequeÃ±a chapuza.</p>
<p>En el fichero .htaccess escribiremos el siguiente texto.</p>
<pre><span style="color: #333333;">ErrorDocument 404 /urlAmigables/controllers/controller.php
</span></pre>
<p><span style="color: #000000;">Esta lÃ­nea que se introduce en el .htaccess significa que si genera el error 404 en el servidor (PÃ¡gina no encontrada) que se vaya a la url /urlAmigables/controllers/controller.php, Es en este fichero donde se va a hacer el procesado de la URL para luego ejecutar dentro las acciones pertinentes.</span></p>
<p>El llamar a esta pÃ¡gina controller.php tiene que ver puesto que esta idea se me ocurriÃ³ aprendiendo a utilizar las Frameworks de PHP, que para mi gusto estÃ¡n bien para hacer desarrollos pequeÃ±os, en desarrollos mÃ¡s grandes es mejor utilizar, desde mi punto de vista, herramientas propias.</p>
<p>En el fichero controller.php debemos introducir:</p>
<div class="igBar"><span id="lphp-2"><a href="#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$URLAmigable</span> = <a href="http://www.php.net/urldecode"><span style="color:#000066;">urldecode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'REQUEST_URI'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; Como en el apache tengo varios sitios en el sito web localhost, tengo que quitar de la url</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// el sitio web sobre el que estoy trabajando.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//$URLAmigable = str_replace('/urlAmigables/', '', $URLAmigable);</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$URLAmigable</span> = <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$URLAmigable</span>, <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//&nbsp; Procesamos la URL Amigable para poder procesar el fichero.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$Params</span> = <a href="http://www.php.net/split"><span style="color:#000066;">split</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/'</span>, <span style="color:#0000FF;">$URLAmigable</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$controller</span> = <span style="color:#FF0000;">''</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/count"><span style="color:#000066;">Count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$Params</span><span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$controller</span> = <span style="color:#0000FF;">$Params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">else</span> <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$URLAmigable</span> != <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$controller</span> = <span style="color:#0000FF;">$URLAmigable</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$strParams</span> = <a href="http://www.php.net/str_replace"><span style="color:#000066;">str_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$controller</span> . <span style="color:#FF0000;">'/'</span>, <span style="color:#FF0000;">''</span>, <span style="color:#0000FF;">$URLAmigable</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">switch</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strtolower"><span style="color:#000066;">strtolower</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$controller</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">"modulo"</span> :</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">"mÃ³dulo"</span> :</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'modulo.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">default</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">''</span>, <span style="color:#000000; font-weight:bold;">true</span>, <span style="color:#CC66CC;color:#800000;">404</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'error404.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>En el IIS en vez de poner el fichero .htaccess, hay que cambiar la url del error 404, si tienes acceso al IIS de tu servidor, deberÃ¡s acceder a Ã©l y luego en el sitio web cambiar las direcciones de error del 404 (por defecto vienen 3) y ponerlas a este fichero. Sino tienes acceso al IIS, seguro que tu servicio de hosting tiene en algÃºn lugar algÃºn sitio donde poder cambiar dicho fichero.</p>
<p>Pues ya estÃ¡ solo hace falta hacer el fichero de error para cuando se introducen direcciones que no son vÃ¡lidas (error404.php) y los ficheros de nuestras herramientas, en el ejemplo es modulo.php, que responde a las url amigables modulo1 y modulo2.</p>
<p>Puedes ver un ejemplo de esta forma de trabajar en <a href="http://urlamigables.petralinkfactory.com">http://urlamigables.petralinkfactory.com</a></p>
<p>Y te puedes descargar el ejemplo desde: <a href="http://urlamigables.petralinkfactory.com/urlamigables.zip">http://urlamigables.petralinkfactory.com/urlamigables.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.petralinkfactory.com/2008/07/15/url-amigables-iiphp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

