For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2005 > URI as parameter to a script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author URI as parameter to a script
greyfade@gmail.com

2005-02-24, 8:55 pm

i hope my subject isn't misleading. take a look at this URL:

http://greyfade.org/test.php

because of how apache handles URLs and because of the information
stored in $_SERVER['PHP_SELF'], i can do nifty things like this:

http://greyfade.org/test.php/2005/24/02

i like the idea of being able to do this, but it looks rather ugly: i
have to put up with having ".php" in my URI, showing off any visitors
to my site that i'm doing strange things.

i want to be able to treat my index.php script as a directory just like
above: http://greyfade.org/6 would point to post #6 instead of to some
file or directory named "6", for example.

in the PHP manual's section on security
<http://us4.php.net/manual/en/security.hiding.php>, an anonymous poster
suggests doing this in the apache configuration:

<VirtualHost *:8080>
DocumentRoot /web/doc_root
Alias /home "/web/doc_root/home.php"
AcceptPathInfo On
</VirtualHost>

this requires two things i don't really have: access to httpd.conf and
Apache 2.

is there any way to do a trick like this on index.php without relying
on the apache RewriteEngine module and without using extensionless
filenames, all under apache 1.3 with only .htaccess files to aid me?

Andy Hassall

2005-02-24, 8:55 pm

On 24 Feb 2005 15:38:13 -0800, "greyfade@gmail.com" <greyfade@gmail.com> wrote:

>i hope my subject isn't misleading. take a look at this URL:
>
>http://greyfade.org/test.php
>
>because of how apache handles URLs and because of the information
>stored in $_SERVER['PHP_SELF'], i can do nifty things like this:
>
>http://greyfade.org/test.php/2005/24/02
>
>i like the idea of being able to do this, but it looks rather ugly: i
>have to put up with having ".php" in my URI, showing off any visitors
>to my site that i'm doing strange things.
>
>i want to be able to treat my index.php script as a directory just like
>above: http://greyfade.org/6 would point to post #6 instead of to some
>file or directory named "6", for example.
>
>in the PHP manual's section on security
><http://us4.php.net/manual/en/security.hiding.php>, an anonymous poster
>suggests doing this in the apache configuration:
>
><VirtualHost *:8080>
> DocumentRoot /web/doc_root
> Alias /home "/web/doc_root/home.php"
> AcceptPathInfo On
></VirtualHost>
>
>this requires two things i don't really have: access to httpd.conf and
>Apache 2.
>
>is there any way to do a trick like this on index.php without relying
>on the apache RewriteEngine module and without using extensionless
>filenames, all under apache 1.3 with only .htaccess files to aid me?


You could probably do it with:

http://httpd.apache.org/docs/mod/mo....html#forcetype
or
http://httpd.apache.org/docs/mod/core.html#defaulttype

... in an .htaccess file, forcing files in your directory to be interpreted as
application/x-httpd-php, provided you've got the relevant AllowOverride
privilege.

According to:

http://httpd.apache.org/docs/mod/co...l#allowoverride

... you probably need at least AllowOverride FileInfo.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Andy Hassall

2005-02-24, 8:55 pm

On Fri, 25 Feb 2005 00:02:51 +0000, Andy Hassall <andy@andyh.co.uk> wrote:

>On 24 Feb 2005 15:38:13 -0800, "greyfade@gmail.com" <greyfade@gmail.com> wrote:
>
>
> You could probably do it with:
>
>http://httpd.apache.org/docs/mod/mo....html#forcetype
>or
>http://httpd.apache.org/docs/mod/core.html#defaulttype
>
> ... in an .htaccess file, forcing files in your directory to be interpreted as
>application/x-httpd-php, provided you've got the relevant AllowOverride
>privilege.
>
> According to:
>
> http://httpd.apache.org/docs/mod/co...l#allowoverride
>
> ... you probably need at least AllowOverride FileInfo.


And now I've posted that I've read enough more of the manual to realise I've
completely missed the point - it's AcceptPathInfo that's missing from Apache
1.3, not how to get extensionless files interpreted as PHP. Whoops.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Matt Mitchell

2005-02-25, 3:56 am

<greyfade@gmail.com> wrote in message
news:1109288293.108203.199600@g14g2000cwa.googlegroups.com...
: <VirtualHost *:8080>
: DocumentRoot /web/doc_root
: Alias /home "/web/doc_root/home.php"
: AcceptPathInfo On
: </VirtualHost>
:
: this requires two things i don't really have: access to httpd.conf and
: apache 2.
:
: is there any way to do a trick like this on index.php without relying
: on the apache RewriteEngine module and without using extensionless
: filenames, all under apache 1.3 with only .htaccess files to aid me?

You can do it with the ErrorDocument directive - handle File Not Found
errors with a PHP script, that then sends a "HTTP/1.1 200 OK" header, and
then includes the relevant file(s), setting the parameters accordingly.


Colin McKinnon

2005-02-25, 8:56 am

greyfade@gmail.com wrote:

>
> because of how apache handles URLs and because of the information
> stored in $_SERVER['PHP_SELF'], i can do nifty things like this:
>
> http://greyfade.org/test.php/2005/24/02
>


Cool!

(I didn't know about that one)

C.

RootShell

2005-02-25, 8:55 pm

Have a look at...

http://www.sitepoint.com/article/guide-url-rewriting

and also this (i think better):

http://www.alistapart.com/articles/slashforward/

It *might* be what you are looking for :)

Regards,
RootShell


RootShell

2005-02-25, 8:55 pm

I forgot this one...


RootShell

2005-02-25, 8:55 pm

I forgot this one...

http://www.alistapart.com/articles/succeed/

Also very good :)

Regards,
RootShell


greyfade@gmail.com

2005-02-26, 3:55 am


RootShell wrote:
> Have a look at...
>
> http://www.sitepoint.com/article/guide-url-rewriting
>
> and also this (i think better):
>
> http://www.alistapart.com/articles/slashforward/
>
> It *might* be what you are looking for :)
>


not quite, no. i don't want to use mod_rewrite if at all possible.

> Regards,
> RootShell


greyfade@gmail.com

2005-02-26, 3:55 am


Matt Mitchell wrote:
> <greyfade@gmail.com> wrote in message
> news:1109288293.108203.199600@g14g2000cwa.googlegroups.com...
> : <VirtualHost *:8080>
> : DocumentRoot /web/doc_root
> : Alias /home "/web/doc_root/home.php"
> : AcceptPathInfo On
> : </VirtualHost>
> :
> : this requires two things i don't really have: access to httpd.conf

and
> : apache 2.
> :
> : is there any way to do a trick like this on index.php without

relying
> : on the apache RewriteEngine module and without using extensionless
> : filenames, all under apache 1.3 with only .htaccess files to aid

me?
>
> You can do it with the ErrorDocument directive - handle File Not

Found
> errors with a PHP script, that then sends a "HTTP/1.1 200 OK" header,

and
> then includes the relevant file(s), setting the parameters

accordingly.


i had considered this, but it seems rather a bit of a kludge to me.
doing this, my entire site quickly becomes one big monolithic
ErrorHandler.

is there anything else at all i could try?

Matt Mitchell

2005-02-27, 3:56 pm

<greyfade@gmail.com> wrote in message
news:1109400419.112002.211240@l41g2000cwc.googlegroups.com...
: > You can do it with the ErrorDocument directive - handle File Not
: Found
: > errors with a PHP script, that then sends a "HTTP/1.1 200 OK" header,
: and
: > then includes the relevant file(s), setting the parameters
: accordingly.
:
:
: i had considered this, but it seems rather a bit of a kludge to me.
: doing this, my entire site quickly becomes one big monolithic
: ErrorHandler.

That's the downside to the solution. On the plus side, you can code it very
economically, just to set the relevant parameters, so in theory your code
*could* be more efficient that apache's rewrite engine, at least for that
specific application.

Don't forget to handle *real* 404's properly...

I keep on meaning to write an ErrorDocument script that will parse a rewrite
..htaccess file, but can never quite be bothered enough to do it! One day
maybe...

: is there anything else at all i could try?

Get a webhost that supports rewrite rules. Really!


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com