On Apr 22, 2008, at 10:35 AM, velda wrote:

Nathan Lane wrote:
So let me clarify for myself (and others information, I guess). Apache web
server needs to have mod_rewrite installed to effectively handle the
requests, but I can just use PHP to rewrite the URLs via the $_SERVER
suprglobal, like this:

<pre>
$_SERVER[]
<?php print_r($_SERVER); ?>
</pre>

I will handle static file requests via the database and a record ID, which
ultimately returns the correct URL to the file to my application and
redirects in order to download the file. Am I on the right track? I'm sure I
just said something that is wrong.

Maybe we're not thinking of the same thing when we say "rewrite" ? I'd
think for a rewrite you need to take a friendly url like this:

/whatever/x/y/ or even
/whatever.php/x/y/

... and make the server _think_ you're actually sending it a query
string like this:

/whatever.php?category=x&item=y

So the contents of the above less friendly url show up when a user or
spider visits the friendly url. I don't know how you'd make php do that on its own, short of actually having /x/ and /y/ directories that display the content for /whatever.php?category=x&item=y .. but at that point why not just generate the content in html?

You're correct. If PHP is doing the handling, it may be better to call it "URL parsing" instead of "URL rewriting". A blog might use 3 scenarios:

1. No Apache rewriting, no PHP parsing:
URL: www.example.com/index.php?type=post&id=123
code: $_GET['type'], $_GET['id']

2. Case specific Apache rewriting, no PHP parsing:
URL: www.example.com/post/123
Apache rewrite: ^(\w+)/(\d+) /index.php?type=$1&id=$2
code: $_GET['type'], $_GET['id']

3. Generic Apache rewriting, PHP parsing:
URL: www.example.com/post/123
Apache rewrite: ^(.*)$ /index.php?url=$1
code: some combination of parse_url(), strtok(), preg_match(), etc. to parse $_GET['url']
This is what WordPress does when you turn on clean URLs.




_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to