NYCPHP Meetup

NYPHP.org

[nycphp-talk] not including '.php' in URI

inforequest 1j0lkq002 at sneakemail.com
Wed Mar 22 14:59:43 EST 2006


Kenneth Dombrowski kenneth-at-ylayali.net |nyphp dev/internal group use| 
wrote:

>for Ajai & Adler, 
>
>mod_rewrite is another way.  here's more of my example from yesterday
>(from an .htaccess file) 
>
>note RewriteLog cannot be set from .htaccess files, so you might have to
>develop your rules locally, on a server you control, and only upload
>them to your hosted account after they work. 
>
># ======================================================================
># RewriteRules to support old-style and friendly URLs
># ======================================================================
># *** For debugging set RewriteLog in httpd.conf *** 
>#
>RewriteEngine On
>#
>#                    F I N A L   R E Q U E S T S
>#
># these are requests for the actual files on disk; stop processing.
>#
>RewriteRule ^catalog.php$               - [NC,L]
>RewriteRule ^account.php$               - [NC,L]
>RewriteRule ^index.php                  - [NC,L]
>RewriteRule ^search.php                 - [NC,L]
>#
>#                          O L D   U R L S
>#
># add support for URLs from old version of site, to avoid breaking
># bookmarks/links/caches.  The redirects will indicate to the user that
># the correct URL has changed (due to [R])
>#
># index.php is no longer the artist search page
>RewriteRule ^index.php?selection=ARTS   catalog/artists [NC,R,L]
>RewriteRule ^index.php?selection=(.*)   catalog/artists/$1 [NC,R,L]
># former by-name searches
>RewriteRule ^index.php?whomlab=(.*)     catalog/label/$1 [NC,R,L]
>RewriteRule ^index.php?whomart=(.*)     catalog/artist/$1 [NC,R,L]
>#
>#                      F R I E N D L Y   U R L S
>#
># (note we are intentionally not using the [R] flag here)
># 
>RewriteRule ^account$                   account.php [NC,L]
>RewriteRule ^account/edit$              account.php?action=edit [NC,L]
>RewriteRule ^catalog/recent$            catalog.php?filter=recent [NC,L]
>RewriteRule ^catalog/artists$           catalog.php?list=artists [NC,L]
># catalog/artist/dead+c -> catalog.php?filter=artist&name=dead+c
>RewriteRule ^catalog/artist/(.*)$       catalog.php?filter=artist&name=$1 [NC,L]
>RewriteRule ^search$                    search.php [NC,L]
>#
># support a few common mistakes (_do_ use the [R] flag here): 
># 
>RewriteRule ^catalog/search$            search.php [NC,L,R]
>  
>
Concrete examples are always helpful. Thanks Ken for the code.

On the other hand, you really need to "see" the part in Ken's code where 
he states the specific objective of his rewrite rule sets.

One section says "final requests" and it stops the filtering...those are 
allowed through as-is. This section comes first. See the beginnings of a 
maintenance problem with this approach?

One section says "old URLs"  -- the objective is to rewrite incoming 
obsolete URLs to their proper content. GIVEN THAT SPECIFIC OBJECTIVE, 
the rulesets are created and tested. Should they send 301's or 302's? 
How long will they exists? Will they ever expire? If so, when were they 
added?

One section says "friendly URLs"... the goal is to make them "memorable" 
or "spider-friendly" or whatever (I am guessing). See how they re-write 
to a script with a parameter set? Se ethe maintenance nightmare 
developing here?

As I recall ken commented earlier about how high maintenance this 
appraoch can be. It is not only application specific, but *platform* 
specific. PHP coder has to play Apache admin, and the conf has to be 
kept updated with the code.

If you want to see a modern approach to this look at WordPress2. The 
rewrite system  grew so complex and is autogenerated (regenerated) and 
cannot really be hand edited or "enhanced" without first earning a 
Master's degree in WordPress Rewriting.

-=john andrews
http://www.seo-fun.com







More information about the talk mailing list