NYCPHP Meetup

NYPHP.org

[nycphp-talk] Do you use Pretty URLs

Rob Marscher rmarscher at beaffinitive.com
Wed Dec 12 12:53:17 EST 2007


On Dec 11, 2007, at 5:31 PM, Cliff Hirsch wrote:
>>> So...how many of you use “pretty urls”? If you do, how do you do it?
> LEGACY APPLICATION.

I recently was able to implement a front controller (http://www.phppatterns.com/docs/design/the_front_controller_and_php 
) that used include() to call old html/php files from a legacy  
application.  There are numerous ways to get all your requests (other  
than those for images, css, js files, and other static resources)  
through my front controller.  Hans Zaunere recommends using AliasMatch  
apache directive if you have access to httpd.conf because it's faster  
than mod_rewrite:

> On Aug 5, 2007, at 2:42 PM, Hans Zaunere wrote:
>> AliasMatch /(.*) "/var/www/www.something.com/index.php"
>
> http://httpd.apache.org/docs/2.0/mod/mod_alias.html#aliasmatch


Anyway... once the urls are going to the front controller, it then  
parsed the query string to figure out the mapping between the current  
url and the legacy version.  The request vars were extracted and  
populated $_REQUEST, $_GET, etc accordingly.  Then I just included the  
file that the url would have gone to and called "exit;" afterwards  
(just in case).  In writing it seems like that would obviously work...  
but I was still surprised that it actually did work.  I found using a  
big switch statement in my front controller and working in php rather  
than a lot of mod_rewrite rules was a bit easier and kept more code in  
the php app rather than spread out between php and apache config  
files.  You should also put 301 header redirects for all of the old  
urls.

The next big task is making sure that all of the url links are  
rewritten properly and that.  That can be fairly difficult if your  
links aren't very centralized.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071212/329ee6a0/attachment.html>


More information about the talk mailing list