Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inclusion page in url

0 views
Skip to first unread message

cobr...@gmail.com

unread,
Sep 16, 2008, 8:23:59 PM9/16/08
to
hello, I have a small doubt that I came while navigating a site
web, practically could see the other pages while
Having always a given page in url, I'll explain with a
example that is much clearer, www.site.it/homepage.php
displaying the front page of the site, but if I did www.site.it/homepage.php#/utenti.php
view list of users, I was wondering how I could
do such a thing in php? I raised this question? : D

thanks

Jerry Stuckle

unread,
Sep 16, 2008, 8:53:54 PM9/16/08
to

You don't need PHP for this - it's straight html and possibly apache
configuration (mod_rewrite).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

Sjoerd

unread,
Sep 17, 2008, 5:04:40 AM9/17/08
to

Say you have the page http://nl.php.net/manual/en/index.php. A request to
http://nl.php.net/manual/en/index.php/any.file.name will also be served
by index.php. In this example, it does not change the page, but the PHP
file may parse the URL and decide to serve something else when the URL is
different.

Anybody knows what this feature is called or why this works like this?

r0g

unread,
Sep 17, 2008, 6:08:10 AM9/17/08
to

Yes, as Jerry says above that's apache's mod_rewrite module.

It's a system that uses regular expressions to pattern match and convert
the URLs you receive in a GET requests into the URLs you actually want.

You specify rewrite directives in you apache config file OR (for
individual users) in htaccess files.

By rewriting the URLS you can change paths into variables e.g.

You receive http://www.poo.poo/images/badgers

and mod_rewrite could change that into:

http://www.poo.poo/imagescript.php?type=badgers

Thereby mapping paths to PHP scripts and variables.

The reference documentation is quite terrifying considering the simple
use cases most people have so I'm not sure I recommend reading and
regular expressions(regex) can take quite a while to get the hang of too
so be prepared to spend a few evenings mastering it! Some useful
examples can be found here:
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

Roger Heathcote.

C. (http://symcbean.blogspot.com/)

unread,
Sep 17, 2008, 7:56:49 AM9/17/08
to
On 17 Sep, 11:08, r0g <aioe....@technicalbloke.com> wrote:
> Sjoerd wrote:
> > On Tue, 16 Sep 2008 17:23:59 -0700, cobra9...@gmail.com wrote:
>
> >> hello, I have a small doubt that I came while navigating a site web,
>
> > Say you have the pagehttp://nl.php.net/manual/en/index.php. A request to
> >http://nl.php.net/manual/en/index.php/any.file.namewill also be served

> > by index.php. In this example, it does not change the page, but the PHP
> > file may parse the URL and decide to serve something else when the URL is
> > different.
>
> > Anybody knows what this feature is called or why this works like this?
>
> Yes, as Jerry says above that's apache's mod_rewrite module.
>

No it's not - it's how apache works **without** mod_rewrite.

I've no idea if this is an apache-specific feature or if other
webservers allow this too.

In order to make use of this you need to parse the contents of
$_SERVER['PHP_SELF']

C.

cobr...@gmail.com

unread,
Sep 17, 2008, 9:14:36 AM9/17/08
to
On 17 Set, 02:53, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> jstuck...@attglobal.net
> ==================

ok thanks to all :)

Jerry Stuckle

unread,
Sep 17, 2008, 10:43:02 AM9/17/08
to

Check again. mod_rewrite needs to be involved. Otherwise your script
will never get control - the user will get a 404 Not Found instead.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

jstu...@attglobal.net
==================

Sjoerd

unread,
Sep 17, 2008, 11:09:45 AM9/17/08
to
On Wed, 17 Sep 2008 10:43:02 -0400, Jerry Stuckle wrote:
>>>> you have the page http://nl.php.net/manual/en/index.php. A request

>>>> to http://nl.php.net/manual/en/index.php/any.file.namewill also be
>>>> served by index.php.
> Check again. mod_rewrite needs to be involved. Otherwise your script
> will never get control - the user will get a 404 Not Found instead.

Not in my experience. The server seems to redirect requests to a "subdir"
of the PHP file to the PHP file itself.

Appearantly, this works not only on my server but on other servers too:
http://nl.php.net/manual/en/index.php/any.file.name
http://www.friendster.com/widgetdirectory.php/any.file.name
http://www.colemaninstitute.org/overview.php/any-file-name

Here, I appended any-file-name, but that gives the same page as without
it and not a 404 Not Found.

Besides, www.colemaninstitute.org seems to be running IIS.

Jerry Stuckle

unread,
Sep 17, 2008, 11:49:59 AM9/17/08
to

Then the server is set up to serve that page instead of a 404 Not Found.

Not really a good idea, IMHO.

r0g

unread,
Sep 17, 2008, 12:07:16 PM9/17/08
to
Jerry Stuckle wrote:
> C. (http://symcbean.blogspot.com/) wrote:
>> On 17 Sep, 11:08, r0g <aioe....@technicalbloke.com> wrote:
>>> Sjoerd wrote:
>>>> On Tue, 16 Sep 2008 17:23:59 -0700, cobra9...@gmail.com wrote:
>>>>> hello, I have a small doubt that I came while navigating a site web,
>>>> Say you have the pagehttp://nl.php.net/manual/en/index.php. A
>>>> request to
>>>> http://nl.php.net/manual/en/index.php/any.file.namewill also be served
>>>> by index.php. In this example, it does not change the page, but the PHP
>>>> file may parse the URL and decide to serve something else when the
>>>> URL is
>>>> different.
>>>> Anybody knows what this feature is called or why this works like this?
>>> Yes, as Jerry says above that's apache's mod_rewrite module.
>>>
>>
>> No it's not - it's how apache works **without** mod_rewrite.
>>
>> I've no idea if this is an apache-specific feature or if other
>> webservers allow this too.
>>
>> In order to make use of this you need to parse the contents of
>> $_SERVER['PHP_SELF']
>>
>> C.
>>
>
> Check again. mod_rewrite needs to be involved. Otherwise your script
> will never get control - the user will get a 404 Not Found instead.
>

Actually he's right, although it sounds like mod rewrite I just tried:

http://www.php.net/downloads.php/test

and it served up exactly the same page as:

http://www.php.net/downloads.php

How odd.

I'm guessing it's a PHP/apache thing rather than an plain apache thing
as: http://httpd.apache.org/index.html/test gives a 404.

My best guess is that, seeing a script in the path apache just tosses
everything to the right of the .php to the PPH interpreter.

Would be interested to see if it works the same was on IIS though.

Regards,

Roger.

Sherm Pendley

unread,
Sep 17, 2008, 12:22:04 PM9/17/08
to
r0g <aioe...@technicalbloke.com> writes:

> Actually he's right, although it sounds like mod rewrite I just tried:
>
> http://www.php.net/downloads.php/test
>
> and it served up exactly the same page as:
>
> http://www.php.net/downloads.php
>
> How odd.

Nothing odd about it at all. PATH_INFO has been around for as long as
CGI scripts have been.

> I'm guessing it's a PHP/apache thing

No, PATH_INFO predates both PHP and Apache.

> Would be interested to see if it works the same was on IIS though.

PATH_INFO works the same way on any standards-compliant server.

sherm--

--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net

r0g

unread,
Sep 17, 2008, 12:27:46 PM9/17/08
to
Sherm Pendley wrote:
> r0g <aioe...@technicalbloke.com> writes:
>
>> Actually he's right, although it sounds like mod rewrite I just tried:
>>
>> http://www.php.net/downloads.php/test
>>
>> and it served up exactly the same page as:
>>
>> http://www.php.net/downloads.php
>>
>> How odd.
>
> Nothing odd about it at all. PATH_INFO has been around for as long as
> CGI scripts have been.
>
>> I'm guessing it's a PHP/apache thing
>
> No, PATH_INFO predates both PHP and Apache.
>

So this behaviour happens even on apache without PHP then??

Roger.

Sherm Pendley

unread,
Sep 17, 2008, 12:38:30 PM9/17/08
to
r0g <aioe...@technicalbloke.com> writes:

Yes, of course. PATH_INFO is a standard CGI variable, available on any
server in any language:

<http://hoohoo.ncsa.uiuc.edu/cgi/env.html>

r0g

unread,
Sep 17, 2008, 2:45:35 PM9/17/08
to
Sherm Pendley wrote:
> r0g <aioe...@technicalbloke.com> writes:
>
>> Sherm Pendley wrote:
>>> r0g <aioe...@technicalbloke.com> writes:
>>>
>>>> Actually he's right, although it sounds like mod rewrite I just tried:
>>>>
>>>> http://www.php.net/downloads.php/test
>>>>
>>>> and it served up exactly the same page as:
>>>>
>>>> http://www.php.net/downloads.php
>>>>
>>>> How odd.
>>> Nothing odd about it at all. PATH_INFO has been around for as long as
>>> CGI scripts have been.
>>>
>>>> I'm guessing it's a PHP/apache thing
>>> No, PATH_INFO predates both PHP and Apache.
>> So this behaviour happens even on apache without PHP then??
>
> Yes, of course. PATH_INFO is a standard CGI variable, available on any
> server in any language:
>
> <http://hoohoo.ncsa.uiuc.edu/cgi/env.html>
>
> sherm--
>

"These environment variables are set when the server executes the
gateway program."

So, to clarify, when you have any scripting/CGI invoked by the URL the
server will eat the rest of the URL and give it to the script/CGI in
this PATH_INFO variable.

When it doesn't (i.e. plain .html files) it'll just throw a 404.

Is this correct?

Sorry if I sound naive but I want to make sure I'm understanding this
properly.

BTW: When I said 'apache without PHP' what I meant was 'apache with no
scripting running, CGI or otherwise'. My bad. I guess I should have been
clearer about that.

Thanks for the insight,

Roger.

Sherm Pendley

unread,
Sep 17, 2008, 3:26:17 PM9/17/08
to
r0g <aioe...@technicalbloke.com> writes:

> Sherm Pendley wrote:
>> r0g <aioe...@technicalbloke.com> writes:
>>
>>> So this behaviour happens even on apache without PHP then??
>>
>> Yes, of course. PATH_INFO is a standard CGI variable, available on any
>> server in any language:
>>
>> <http://hoohoo.ncsa.uiuc.edu/cgi/env.html>
>

> "These environment variables are set when the server executes the
> gateway program."
>
> So, to clarify, when you have any scripting/CGI invoked by the URL the
> server will eat the rest of the URL and give it to the script/CGI in
> this PATH_INFO variable.

Yes, exactly. Suppose you have a URL like this:

<http://foo.invalid/index.php/bar/baz/qux>

Now, supposing your base HTML directory is /home/html, when index.php
is executed the value of PATH_INFO will be '/bar/baz/qux', and that of
PATH_TRANSLATED will be '/home/html/bar/baz/qux'.

> When it doesn't (i.e. plain .html files) it'll just throw a 404.
>
> Is this correct?

Right. CGI variables aren't passed to static content, because there
would be no point in doing so - static content, by definition, would
not be able to use them anyway.

Message has been deleted

cobr...@gmail.com

unread,
Sep 17, 2008, 10:10:00 PM9/17/08
to
On 17 Set, 02:53, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> jstuck...@attglobal.net
> ==================

but i have other request, how to i use a char # in file htacces if is
comment ?

example on really site:

http://www.new.facebook.com/home.php

http://www.new.facebook.com/home.php#/notifications.php

ecc . . .

cobra90nj

Jerry Stuckle

unread,
Sep 17, 2008, 11:31:48 PM9/17/08
to
cobr...@gmail.com wrote:
> On 17 Set, 02:53, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> jstuck...@attglobal.net
>> ==================
>
> but i have other request, how to i usa a char # in file htacces if is

> comment ?
>
> example on really site:
>
> http://www.new.facebook.com/home.php
>
> http://www.new.facebook.com/home.php#/notifications.php
>
> ecc . . .
>
>
>
> cobra90nj
>

Try alt.apache.configuration. This is NOT a PHP question.

Michael Fesser

unread,
Sep 18, 2008, 11:43:26 AM9/18/08
to
.oO(cobr...@gmail.com)

>but i have other request, how to i usa a char # in file htacces if is
>comment ?

The # separates the URL from the fragment identifier. The server will
never see it. If you want that char to appear in your URLs, you have to
encode it.

Technically it's the same URL. The latter just contains a (invalid)
fragment identifier, which is handled by the browser.

Micha

John Dunlop

unread,
Sep 18, 2008, 6:49:47 PM9/18/08
to
Michael Fesser:

> >http://www.new.facebook.com/home.php
>
> >http://www.new.facebook.com/home.php#/notifications.php
>
> Technically it's the same URL. The latter just contains a (invalid)
> fragment identifier, which is handled by the browser.

RFC 3986 allows the fragment identifier </notifications.php> and HTML
allows the (a element) name attribute value "/
notifications.php" (although the same value for the id attribute would
be invalid).

--
Jock

Michael Fesser

unread,
Sep 19, 2008, 12:42:11 PM9/19/08
to
.oO(John Dunlop)

Yes. See my reply in the other thread about the names on form controls.
Same thing.

Micha

0 new messages