You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Chris Simon <os...@zetnet.co.uk> on 2004/10/13 14:21:01 UTC

[users@httpd] Content Negotiation and PHP

I have web hosting with a company called 1&1, running Apache 1.3. 
Although their content negotiation appears to be working correctly for 
most files (.html, .jpg, .gif etc, and also language negotiation) I 
can't work out how to get PHP pages to negotiate.  I'm not getting any 
help from 1&1 - they won't give advice on user programming!

As far as I can see, all I should need to do is add the following to my 
.htaccess file (I obviously do not have access to the server config files):

AddType application/x-httpd-php .php
Options +MultiViews

I've worked this out from searching on the web.  But I suspect this 
might only be for Apache 2?  I have Apache 2 at home and it works 
perfectly with the AddType directive in httpd.conf.

If I call up a file with the .php extension, the page is parsed correctly.

If a call it without the extension, then I want it to find the file 
*with* the extension.  But all I get is a 404 Not Found.

Can anyone help?

-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Chris Simon <os...@zetnet.co.uk>.
Joshua Slive wrote:
> I'm not sure exactly what is going on here, but I suspect you are
> using a messed up apach or php install.  In particular, if you look at
> the Content-Location header in the HTTP response, you'll see that it
> properly points to tt.php.  But for some reason, the subrequest to
> deliver that file fails.  I have no idea why.

Note that at the moment I haven't got the AddType directive in my 
.htaccess as I have a test forum on the site that I wanted my users to 
have a look at, and putting the AddType directive in causes all requests 
to PHP files to fail (the browser tries to download the file instead of 
rendering it because the MIME type is wrong).  So I now think the 404 
Not Found error is a red herring - it's just a symptom of my ISP not 
having AddType in the main config file.


-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Robert Andersson <ro...@profundis.nu>.
Chris Simon wrote:
> Yes, it's extension hiding that I really want, not the negotiation, as 
> there will not be both .html and .php files of the same name.  I just want 
> to write my site with extensionless links from the start using .html 
> files, then in the future rename them to .php without breaking links or 
> bookmarks.

I wish more people were as thoughtful as you. However, I think having URIs 
ending in .html is OK, since that is the format the client gets regardless 
if it is PHP, ASP, Perl that is generating it.

> The only problem is if the rewrite will cause the extension to appear
> in the address bar

No, not unless you append the [R] flag to the rewrite rule. As it was, it 
should be an internal redirect.

You can also have a rule like this:
    RewriteRule ^(test1|test2|test3)$ $1.php [L]

However, if you have many documents, I suggest trying my other alternative, 
that automatically rewrites "all" requests that exists with the extension 
added.

Regards,
Robert Andersson 


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Chris Simon <os...@zetnet.co.uk>.
Robert Andersson wrote:
> As a workaround you can always use mod_rewrite to internally redirect 
> the requests. IF you do this to avoid the file extension, and not the 
> true purpose, that is, negotiation.
> 
> Specifically:
> 
>    RewriteEngine On
>    RewriteRule ^test$ test.php [L]

I'll have a play with that.  Thank you for the suggestion.

Yes, it's extension hiding that I really want, not the negotiation, as 
there will not be both .html and .php files of the same name.  I just 
want to write my site with extensionless links from the start using 
.html files, then in the future rename them to .php without breaking 
links or bookmarks.  The only problem is if the rewrite will cause the 
extension to appear in the address bar - I would want the URL to remain 
as the requested URL, not the URL that was found.

-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Robert Andersson <ro...@profundis.nu>.
Chris Simon wrote:
> And when I first contacted 1&1 to ask them what I should put in
> my .htaccess file, they just replied that they won't help with
> personal development!  Oh well, I'll continue...

In this case, it very much looks like they have a non-standard or faulty 
configuration. They might not be aware of the problem, since not many use 
content negotiation this way.

As a workaround you can always use mod_rewrite to internally redirect the 
requests. IF you do this to avoid the file extension, and not the true 
purpose, that is, negotiation.

Specifically:

    RewriteEngine On
    RewriteRule ^test$ test.php [L]

Or, you can try a more general approach:

    RewriteEngine On
    RewriteCond /your/doc/root%{REQUEST_URI}.php -f
    RewriteRule (.*) $1.php

Regards,
Robert Andersson 


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Chris Simon <os...@zetnet.co.uk>.
Robert Andersson wrote:
> I suggest you contact the admins so they can look into it. Only they 
> (hopefully) know how the main server is configured.

OK. I think I've established now what *should* be done, it's just a 
question of finding out from 1&1 how to do it in their particular 
installation.  It may be that they can't support full content 
negotiation - I know that Titan and Nethosted can't do it.  And when I 
first contacted 1&1 to ask them what I should put in my .htaccess file, 
they just replied that they won't help with personal development!  Oh 
well, I'll continue...

-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Robert Andersson <ro...@profundis.nu>.
Chris Simon wrote:
> In both cases, the browser pops up a Download File dialog box because the 
> MIME type is not text/html.

If PHP handles the file, it will reset the Content-Type to text/html, so 
this behaviour implies that PHP does not handle it.

The issue here might be that they use a different MIME type, eg. 
application/x-httpd-php3 or something, and your AddType overrides that, thus 
resulting in PHP not working.

I'm not sure why you should need to use AddType at all, isn't PHP files 
already recognized?

I'm with Joshua, the server seems messed up. The giveaway is the 404, while 
it still have the Content-location header set correctly.

I suggest you contact the admins so they can look into it. Only they 
(hopefully) know how the main server is configured.

Regards,
Robert Andersson 


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Apache Authentication

Posted by Joshua Slive <js...@gmail.com>.
On Sun, 17 Oct 2004 05:17:40 -0700 (PDT), faisal gillani
<fa...@yahoo.com> wrote:
> i want to know how to allow only the users in my
> /etc/passwd file to access my website ?

See:
http://httpd.apache.org/docs/misc/FAQ.html#passwdauth
for why this is a very bad idea.

If you still want to do it, there are several modules under
http://modules.apache.org/ that can do the job.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Chris Simon <os...@zetnet.co.uk>.
Nick Kew wrote:
>>Options +MultiViews
>>AddType application/x-httpd-php .php
> 
> 
> Haven't you posted that and had it answered already?
> 
> That kind of AddType hack is a relic from the NCSA (pre-Apache) server.
> It's a workaround for a design defect, long since fixed.  It is obsoleted
> by the introduction of AddHandler and not dispatching on content-type.
> 
> I'm not sure why you're trying to do this with content negotiation.
> Why not just use SetHandler in a <Files>?

I'm using it because that's what the Apache documentation tells me to do 
and what all pages I've searched for tell me to do and the advice given 
so far in all forums and discussion groups!

Can you explain what to put in a SetHandler directive then?  How do I 
use that?

I've tried the following (found in only one web page and advised on this 
mailing list that it *should* work in Apache 1.3 even though it was only 
intended for Apache 2.0):

AddHandler php-script php
AddType text/html php

But the effect this has is to give me the source of the PHP, not the 
result of the PHP.  In other words, the file is not being passed to the 
PHP parser.

Please see the following:

http://www.nantperis.org.uk/test/test - .htaccess with MultiViews & AddType
http://www.nantperis.org.uk/test2/test - .htaccess with just MultiViews
http://www.nantperis.org.uk/test3/test - .htaccess with AddHandler & AddType

-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Apache Authentication

Posted by faisal gillani <fa...@yahoo.com>.
i want to know how to allow only the users in my
/etc/passwd file to access my website ? 


thanks

=====
*��., ��,.��*���*� Allah-hu-Akber*��., ��,.��*��*�


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Nick Kew <ni...@webthing.com>.
On Wed, 13 Oct 2004, Chris Simon wrote:

> Options +MultiViews
> AddType application/x-httpd-php .php

Haven't you posted that and had it answered already?

That kind of AddType hack is a relic from the NCSA (pre-Apache) server.
It's a workaround for a design defect, long since fixed.  It is obsoleted
by the introduction of AddHandler and not dispatching on content-type.

I'm not sure why you're trying to do this with content negotiation.
Why not just use SetHandler in a <Files>?

-- 
Nick Kew

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Chris Simon <os...@zetnet.co.uk>.
I have now created a new folder with its own .htaccess file consisting 
of just the following:

Options +MultiViews
AddType application/x-httpd-php .php

Try calling it up the test.php file that is in the folder both with and 
without the .php extension, i.e.

http://www.nantperis.org.uk/test/test.php
http://www.nantperis.org.uk/test/test

In both cases, the browser pops up a Download File dialog box because 
the MIME type is not text/html.

If I was to remove the AddType command from .htaccess, it would execute 
the file properly if you call it with the .php extension, but produce a 
404 Not Found if you call it without the extension.

-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Joshua Slive <js...@gmail.com>.
I'm not sure exactly what is going on here, but I suspect you are
using a messed up apach or php install.  In particular, if you look at
the Content-Location header in the HTTP response, you'll see that it
properly points to tt.php.  But for some reason, the subrequest to
deliver that file fails.  I have no idea why.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Chris Simon <os...@zetnet.co.uk>.
It strikes me that the AddType command is indeed what I should be using 
(with the .php extension) as 1&1 haven't got this in their config file - 
which is perfectly OK.  But the server is not returning the page as 
text/html, instead as application/x-httpd-php which obviously the 
browser doesn't understand and tries to dwnload it to disk instead.

So...internally Apache needs to know the source is 
application/x-httpd-php so that it can send it to the PHP parser for 
processing, but the resulting file needs to come to the browser as 
text.html.  Where is the missing link??  What tells Apache/PHP to retrn 
files as HTML?

All I've got is the following command:

AddType application/x-httpd-php .php

Does this tell Apache internally that the file is PHP, or does it tell 
Apache to return the page to the browser as PHP, not HTML?  Or does it 
do both, and can I add another command to change the MIME type of the 
resulting file to HTML?


-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Chris Simon <os...@zetnet.co.uk>.
Joshua Slive wrote:
> If you are really getting 404, then the problem is that your Options
> directive is not applied in the correct place in the config file. 
> See:
> http://httpd.apache.org/docs/misc/FAQ.html#options

Yep, it's definitely a 404.  Please try it at 
http://www.nantperis.org.uk/tt - but if you call it with 
http://www.nantperis.org.uk/tt.php then it works.  Note that Content 
Negotiation *is* working on the site because 
http://www.nantperis.org.uk/contact works, which is a html file.  And in 
fact the main URL http://www.nantperis.org.uk/ works and it's language 
negotiated as well - the filename is actually index.html.en and 
index.html.cy.  It's only the PHP negotiation that doesn't work.

I've read the link you gave but it only applies I think to Options 
directives that are "absolute".  I have a plus character before the 
MultiViews parameter which makes it "relative" so that all the other 
options don't get reset. My .htaccess file is simply the two lines I 
gave before:

Options +MultiViews
AddLanguage en .en
AddLanguage cy .cy

I've tried adding the AddType directive but this causes both URLs (with 
and without the .php extension) to produce a browser dialog asking me to 
download a file of type application/x-httpd-php instead of rendering the 
page.

I've tried the fix on the other link you gave:

Replace the AddType line with:

AddHandler php-script php
AddType text/html php

This causes the Content Negotiation to work and the file to be found, 
but it's parsed as HTML and the PHP bits are ignored.

Does this point towards the web host's configuration being wrong?

-- 
Chris Simon
   osian@zetnet.co.uk
   http://www.users.zetnet.co.uk/csimon/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content Negotiation and PHP

Posted by Joshua Slive <js...@gmail.com>.
On Wed, 13 Oct 2004 13:21:01 +0100, Chris Simon <os...@zetnet.co.uk> wrote:
> I have web hosting with a company called 1&1, running Apache 1.3.
> Although their content negotiation appears to be working correctly for
> most files (.html, .jpg, .gif etc, and also language negotiation) I
> can't work out how to get PHP pages to negotiate.  I'm not getting any
> help from 1&1 - they won't give advice on user programming!
> 
> As far as I can see, all I should need to do is add the following to my
> .htaccess file (I obviously do not have access to the server config files):
> 
> AddType application/x-httpd-php .php
> Options +MultiViews
> 
> I've worked this out from searching on the web.  But I suspect this
> might only be for Apache 2?  I have Apache 2 at home and it works
> perfectly with the AddType directive in httpd.conf.
> 
> If I call up a file with the .php extension, the page is parsed correctly.
> 
> If a call it without the extension, then I want it to find the file
> *with* the extension.  But all I get is a 404 Not Found.

If you are really getting 404, then the problem is that your Options
directive is not applied in the correct place in the config file. 
See:
http://httpd.apache.org/docs/misc/FAQ.html#options

You may also be getting a "no acceptable variants" error, in which
case you should see:
http://tranchant.plus.com/notes/multiviews
which should work in 1.3, even though it says it only works in 2.0.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org