Re: php/apache url cleanup

From: kracker <thekracker@gmail.com>
Date: Wed Dec 29 2004 - 19:10:55 AKST

schu's right!

Depending on the scope of the code in question, it might prove to be
closer to a rewrite than just making it work the way you want.

Congratulations are definitely in order as what bothers you about long
meaningless urls is the sloppy way of web app programing.

Designing a simple solution is worth it in most cases, this is
outlined in w3.org guidelines as "the way urls (things) ought to be".

While what you want to do seems simple, doing so can prove to be a bit
more involved.

The tool you want to uses is an apache module (almost always enabled)
called mod_rewrite. Mod Rewrite is a very powerful tool which can do
about 90% of what you want to do. A side effect is that the code may
depend on certain variables being passed using &'s, just about all of
these dependencies can be resolved with a more thought out /
simplified variable / action design.

Mod rewrite is a test of your ability to understand urls, uris, apache
and regular expressions. It's no simple task for most people. Most
people give up before making the breakthroughs needed to effectively
yield mod_rewrite.

mod_rewrite, the Swiss Army Knife of URL manipulation!

What always seems to crank me (less so these days) is that a lot of
applications are simply not designed to meet the w3c's recommendations
which address these design issues. From a programing perspective it's
a big bite to dig into, but the advantages after mastering the tools
needed to solve these problems greatly expands your ability to design
very simple web application's url / uri api. It's worth the time if
you can handle it.

The web applications I regularly were designed and built using
mod_rewrite from the beginning which really helps as the application
expects the urls to be simple and clean instead of the other kind...

            ``The great thing about mod_rewrite is it gives you all
the configurability and flexibility of Sendmail. The downside to
mod_rewrite is that it gives you all the configurability and
flexibility of Sendmail.''
            -- Brian Behlendorf
            Apache Group

            `` Despite the tons of examples and docs, mod_rewrite is
voodoo. Damned cool voodoo, but still voodoo. ''
            -- Brian Moore
            bem@news.cmc.net

I ran across these community sites and documentation which have some
forums and examples to get started with:

http://www.mod-rewrite.com/

http://www.modrewrite.com/

http://httpd.apache.org/docs/mod/mod_rewrite.html

http://www.google.com/search?hl=en&q=mod_rewrite&btnG=Google+Search

I know just enough to get myself into trouble and I've only been
hitting the books for the past 4 years, so it might take a while to
grok mod_rewrite.

That said I bet with a little hard work you can put together a basic
working implementation that meets your needs.
 
My next pet peeve in web app url api's : amazon style urls

//kracker
pbs : netscape : code rush

On Wed, 29 Dec 2004 17:14:46 -0900, Matthew Schumacher <schu@schu.net> wrote:
> Clay Scott wrote:
> > i'm working on a little web-based app and i'm gettting annoyed with the mile-long urls that are generated from passing information from script to script. i'm trying to clean this up by eliminating the miles of ?foo=foo&bar=bar and replacing it with something sane and clearly readable.
> >
> > it's software for cataloging books so instead of having browse.php?art=Publisher i'm trying to change things to be www.host.com/browse/publisher. i've gotten it to work as long as i leave it as www.host.com/browse.php/publisher, but i want to get rid of the .php's completely.
> >
> > i tried adding a .htaccess file to the directories as such:
> >
> > RewriteEngine On
> > RewriteRule book book.php
> > RewriteRule browse browse.php
> >
> > it got the job done and i can properly view host.com/browse, but this prevents the scripts from getting variables from the url. my intention is to get it to where i can do www.host.com/book/213 and it'll display the details for book number 213 in my database. as i said, my only fix thus far is to type www.host.com/browse.php/213. i know it's possible, i've seen done on plenty of sites so if the explanation is a bit long-winded a link to a page explaining it or some proof-of-concept code would be greatly appreciated.
> >
> > thanks,
> > ~clay
> >
>
> I very well may be wrong, (I haven't looked at it in a while) but I
> think that your going to run into a lot of heartache trying to get
> apache to work like that. I wouldn't be surprised if there was a way to
> make it work, but your always going to be running the risk of some other
> code/config later on not wanting to play nice.
>
> On some stuff I have done I just make php parse all of my html documents
> (which all use php code anyway) then do all of my vars in a server side
> session variable. That way I can keep track of what is going on and the
> only thing I pass back and forth to the client is the token and it's
> automatic in php. One nice feature of this setup is that you always
> know what the user did. Suppose the user sorted some data, then left
> the screen and came back, the sort var is still set until it is
> overwritten with new information so the user finds what they expect
> instead of the data set back to the default sorting.
>
> schu
>
> ---------
> To unsubscribe, send email to <aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>
>
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed Dec 29 19:10:58 2004

This archive was generated by hypermail 2.1.8 : Wed Dec 29 2004 - 19:10:58 AKST