473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Hiding PHP extension

I'm supposed to hide the php extension in a file (like Yahoo! or
Google). For example, http://foo.com/foo instead of
http://foo.com/foo.php. I have read various articles including
<http://in2.php.net/security.hiding> . Certainly mod_rewrite is not
the right option. In Apache, "file.php" & "file" are treated as same
(content negotiation??) and like to know, how reliable it is? Is there
any other options to do the same? TIA

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #1
21 6453
R. Rajesh Jeba Anbiah <ng**********@rediffmail.com> wrote or quoted:
I'm supposed to hide the php extension in a file
(like Yahoo! or Google). For example, http://foo.com/foo
instead of http://foo.com/foo.php.


Use http://foo.com/foo/ instead.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #2
On Fri, 02 Apr 2004 10:21:15 +0000, Tim Tyler wrote:
R. Rajesh Jeba Anbiah <ng**********@rediffmail.com> wrote or quoted:
I'm supposed to hide the php extension in a file
(like Yahoo! or Google). For example, http://foo.com/foo
instead of http://foo.com/foo.php.


Use http://foo.com/foo/ instead.

This will fail.. as it will look for a directory. The OP has it right..
and I don't forsee any issues with the way they have it.. although I maybe
missing some hidden issues.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #3
R. Rajesh Jeba Anbiah wrote:
For example, http://foo.com/foo instead of
http://foo.com/foo.php. Is there
any other options to do the same? TIA


I do:

..htaccess in DocumentRoot

ErrorDocument 404 /notfound.php
and /notfound.php

<?php
// validate $_SERVER['REQUEST_URI']
// and either {
// show some specific page/data
// } or {
// show error message
// }
?>

So if you go to http://example.com/foo and /foo does not exist,
/notfound.php will take control and can include/require or redirect to
/foo.php

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #4
Pedro Graca wrote:
Is there
any other options to do the same? TIA


I do:

.htaccess in DocumentRoot

ErrorDocument 404 /notfound.php
and /notfound.php

<?php
// validate $_SERVER['REQUEST_URI']
// and either {
// show some specific page/data
// } or {
// show error message
// }
?>

So if you go to http://example.com/foo and /foo does not exist,
/notfound.php will take control and can include/require or redirect to
/foo.php


Wouldn't this just return a 404 header and the content (thereby telling
any search engines to remove it from their list as you wouldn't normally
have valid content in a 404 page).

Cheers,
Andy
Jul 17 '05 #5
Andy Jeffries wrote:
Pedro Graca wrote:
I do:

.htaccess in DocumentRoot

ErrorDocument 404 /notfound.php
and /notfound.php

<?php
// validate $_SERVER['REQUEST_URI']
// and either {
// show some specific page/data
// } or {
// show error message
// }
?>
Wouldn't this just return a 404 header and the content (thereby telling
any search engines to remove it from their list as you wouldn't normally
have valid content in a 404 page).


Yes, it would ... unless you also send a

header('HTTP/1.0 200 OK');

which overrides Apache's behaviour.

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #6
On 1 Apr 2004 22:08:14 -0800, ng**********@rediffmail.com (R. Rajesh Jeba
Anbiah) wrote:
In Apache, "file.php" & "file" are treated as same
(content negotiation??) and like to know, how reliable it is?


I've been using this for a while and have had no problem with it. Just
remember to set Options MultiViews.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #7
put this in an .htaccess file

DefaultType application/x-httpd-php

This will make all unknow filetype to be considered as php file.

Savut

"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
I'm supposed to hide the php extension in a file (like Yahoo! or
Google). For example, http://foo.com/foo instead of
http://foo.com/foo.php. I have read various articles including
<http://in2.php.net/security.hiding> . Certainly mod_rewrite is not
the right option. In Apache, "file.php" & "file" are treated as same
(content negotiation??) and like to know, how reliable it is? Is there
any other options to do the same? TIA

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com


Jul 17 '05 #8
On Fri, 2 Apr 2004 14:16:01 -0500, "Savut" <we***@hotmail.com> wrote:
put this in an .htaccess file

DefaultType application/x-httpd-php

This will make all unknow filetype to be considered as php file.


This really isn't a good idea.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #9
But this is what you HAVE TO DO to do it, you just have tu put your files
and the .htaccess file in a special folder, and this rule apply only to the
folder, just like the cgi-bin works. That's what major compagny do, and it
work more normaly than the others solutions as the rule is designed for to
do this job.

Savut

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:i3********************************@4ax.com...
On Fri, 2 Apr 2004 14:16:01 -0500, "Savut" <we***@hotmail.com> wrote:
put this in an .htaccess file

DefaultType application/x-httpd-php

This will make all unknow filetype to be considered as php file.


This really isn't a good idea.

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


Jul 17 '05 #10
On Fri, 2 Apr 2004 15:15:16 -0500, "Savut" <we***@hotmail.com> wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:i3********************************@4ax.com.. .
On Fri, 2 Apr 2004 14:16:01 -0500, "Savut" <we***@hotmail.com> wrote:
put this in an .htaccess file

DefaultType application/x-httpd-php

This will make all unknow filetype to be considered as php file.


This really isn't a good idea.


But this is what you HAVE TO DO to do it, you just have tu put your files
and the .htaccess file in a special folder, and this rule apply only to the
folder, just like the cgi-bin works. That's what major compagny do, and it
work more normaly than the others solutions as the rule is designed for to
do this job.


What's wrong with using Options MultiViews?

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #11
Because you dont control how Apache find the next file when he dont file
your file.

[...]
The effect of MultiViews is as follows: if the server receives a request for
/some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does
not exist, then the server reads the directory looking for files named
foo.*, and effectively fakes up a type map which names all those files,
assigning them the same media types and content-encodings it would have if
the client had asked for one of them by name. It then chooses the best match
to the client's requirements.
[...]

And also, Multiviews, his job is to send a file when something is not found,
but that is looking similar than the file that was requested, if you want
http://www.domain.com/foo and it dont exist, the server will search for
http://www.domain.com/foo.txt or http://www.domain.com/foo.php,
http://www.domain.com/foo.dat, and so on until he find one.If you have
something like foo.txt and a file foo, what will happen, who come first ?
And for performance, it is sure slower as the server has to try all the
cases.

I dont said it wont work, but that not the right way to do it.

Savut

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:f3********************************@4ax.com...
On Fri, 2 Apr 2004 15:15:16 -0500, "Savut" <we***@hotmail.com> wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:i3********************************@4ax.com. ..
On Fri, 2 Apr 2004 14:16:01 -0500, "Savut" <we***@hotmail.com> wrote:

put this in an .htaccess file

DefaultType application/x-httpd-php

This will make all unknow filetype to be considered as php file.

This really isn't a good idea.


But this is what you HAVE TO DO to do it, you just have tu put your files
and the .htaccess file in a special folder, and this rule apply only to
the
folder, just like the cgi-bin works. That's what major compagny do, and
it
work more normaly than the others solutions as the rule is designed for to
do this job.


What's wrong with using Options MultiViews?

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


Jul 17 '05 #12
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
I'm supposed to hide the php extension in a file (like Yahoo! or
Google). For example, http://foo.com/foo instead of
http://foo.com/foo.php. I have read various articles including
<http://in2.php.net/security.hiding> . Certainly mod_rewrite is not
the right option. In Apache, "file.php" & "file" are treated as same
(content negotiation??) and like to know, how reliable it is? Is there
any other options to do the same? TIA


Why isn't mod_rewrite the right option?
Jul 17 '05 #13
<previous post>
I'm supposed to hide the php extension in a file (like Yahoo! or
Google). For example, http://foo.com/foo instead of
http://foo.com/foo.php. I have read various articles including
<http://in2.php.net/security.hiding> . Certainly mod_rewrite is not
the right option. In Apache, "file.php" & "file" are treated as same
(content negotiation??) and like to know, how reliable it is? Is there
any other options to do the same? TIA

</previous post>
Many thanks to all the experts who answered in this thread. The
advantage I have found in MultiViews (thanks for correcting:-)) is
that we can use $_SERVER['PHP_SELF'] and other variables instead of
hard coding the links. Similarly, I hope, in Savut's suggestion also,
there won't be much problem. While searching I read one of the article
which says, Yahoo! uses some strange extensions like .unknown 'coz of
security and then apply mod_rewrite; but not sure about it and the
performance, In that case, they may hard code the links (they may not
use $_SERVER['PHP_SELF'] or so).

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #14
Ian.H <ia*@windozedigiserv.net> wrote or quoted:
On Fri, 02 Apr 2004 10:21:15 +0000, Tim Tyler wrote:
R. Rajesh Jeba Anbiah <ng**********@rediffmail.com> wrote or quoted:
I'm supposed to hide the php extension in a file
(like Yahoo! or Google). For example, http://foo.com/foo
instead of http://foo.com/foo.php.


Use http://foo.com/foo/ instead.


This will fail.. as it will look for a directory.


Uh - that was the point.

The most correct way to encapuslate files using a web server (so their
extensions are not directly exposed to the client) is to use index files
in directories.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #15
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<vu********************@comcast.com>...
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
I'm supposed to hide the php extension in a file (like Yahoo! or
Google). For example, http://foo.com/foo instead of
http://foo.com/foo.php. I have read various articles including
<http://in2.php.net/security.hiding> . Certainly mod_rewrite is not
the right option. In Apache, "file.php" & "file" are treated as same
(content negotiation??) and like to know, how reliable it is? Is there
any other options to do the same? TIA


Why isn't mod_rewrite the right option?


Applying mod_rewrite results in hard coding the links or force us
to implement a system to taken care of linking. Apart from this major
drawback, it seems to have performance constraints too (few articles
hint this).

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #16
> Ian.H <ia*@windozedigiserv.net> wrote or quoted:
On Fri, 02 Apr 2004 10:21:15 +0000, Tim Tyler wrote:
R. Rajesh Jeba Anbiah <ng**********@rediffmail.com> wrote or quoted: I'm supposed to hide the php extension in a file
> (like Yahoo! or Google). For example, http://foo.com/foo
> instead of http://foo.com/foo.php.

Use http://foo.com/foo/ instead.


This will fail.. as it will look for a directory.


I could see, that Ian's and few others' messages are not appearing
in Google Groups (for example
<http://groups.google.com/groups?threadm=abc4d8b8.0404012208.76ebdba7%40post ing.google.com>).
By any chance, their News Reader may be configured with "X-No-archive"
headers <http://www.google.com/googlegroups/help.html#prevent> . If
that is the case, I suggest to remove it. Thanks.

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #17
DefaultType application/x-httpd-php is more better

Imagine your application contain lot of files and you need something like

http://www.domain.com/openWork/submit?var1=true&var2=10
http://www.domain.com/openWork/list?num=30
http://www.domain.com/openWork/docha...ion=1234455632

Yahoo work like this way and most big corporate do also to hide their
application extension.

But again, the way they do it is using cgi-directory. If you have
configured PHP this way and configurer Apache to handle it, you can do the
same than them, just put this on the first line of your php files
#!/usr/bin/php or #!c:/php/bin/php.exe (windows)
then the server will call php to process these files, so the extensions are
not used. You can decide to not use any extension.

Savut

"Tim Tyler" <ti*@tt1lock.org> wrote in message news:Hv********@bath.ac.uk...
Ian.H <ia*@windozedigiserv.net> wrote or quoted:
On Fri, 02 Apr 2004 10:21:15 +0000, Tim Tyler wrote:
> R. Rajesh Jeba Anbiah <ng**********@rediffmail.com> wrote or quoted: >> I'm supposed to hide the php extension in a file
>> (like Yahoo! or Google). For example, http://foo.com/foo
>> instead of http://foo.com/foo.php.
>
> Use http://foo.com/foo/ instead.


This will fail.. as it will look for a directory.


Uh - that was the point.

The most correct way to encapuslate files using a web server (so their
extensions are not directly exposed to the client) is to use index files
in directories.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.


Jul 17 '05 #18
Savut <we***@hotmail.com> wrote or quoted:

[Re: "Hiding PHP's extension? Use http://foo.com/foo/"]
DefaultType application/x-httpd-php is more better

Imagine your application contain lot of files and you need something like

http://www.domain.com/openWork/submit?var1=true&var2=10
http://www.domain.com/openWork/list?num=30
http://www.domain.com/openWork/docha...ion=1234455632

Yahoo work like this way and most big corporate do also to hide their
application extension.


I would use www.domain.com/openWork/list/?num=30

That way it still works if you don't have access to the innards
of the webserver - if .htaccess is turned off on security grounds,
or if your webesrver is shared - and different clients have
conflicting needs about what is the default handler.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #19
If someone can't use .htaccess because the hosting prohibit it, well I
suggest to change the hosting company because he miss a lot of features that
an .htaccess file can do. :D

Savut

"Tim Tyler" <ti*@tt1lock.org> wrote in message news:Hv********@bath.ac.uk...
Savut <we***@hotmail.com> wrote or quoted:

[Re: "Hiding PHP's extension? Use http://foo.com/foo/"]
DefaultType application/x-httpd-php is more better

Imagine your application contain lot of files and you need something like

http://www.domain.com/openWork/submit?var1=true&var2=10
http://www.domain.com/openWork/list?num=30
http://www.domain.com/openWork/docha...ion=1234455632

Yahoo work like this way and most big corporate do also to hide their
application extension.


I would use www.domain.com/openWork/list/?num=30

That way it still works if you don't have access to the innards
of the webserver - if .htaccess is turned off on security grounds,
or if your webesrver is shared - and different clients have
conflicting needs about what is the default handler.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.


Jul 17 '05 #20
Savut <we***@hotmail.com> wrote or quoted:
If someone can't use .htaccess because the hosting prohibit it, well I
suggest to change the hosting company because he miss a lot of features that
an .htaccess file can do. :D


Use of ".htaccess" is *often* turned off - on grounds of performance and
security [1].

I can't see why should I instruct people to change their site hosting so
they can run my software - when there's no need for me to force them to
do so.

Lastly, .htaccess is an apache-specific feature. Apache is not the
only PHP server in existence - and I would prefer my software to be
portable.

[1] ".htaccess files, Apache Tutorial"

``There are two main reasons to avoid the use of .htaccess
files.

The first of these is performance. When AllowOverride is set
to allow the use of .htaccess files, Apache will look in
every directory for .htaccess files. Thus, permitting
.htaccess files causes a performance hit, whether or not you
actually even use them! Also, the .htaccess file is loaded
every time a document is requested.

Further note that Apache must look for .htaccess files in
all higher-level directories, in order to have a full
complement of directives that it must apply. (See section on
how directives are applied.) Thus, if a file is requested
out of a directory /www/htdocs/example, Apache must look for
the following files:

/.htaccess
/www/.htaccess
/www/htdocs/.htaccess
/www/htdocs/example/.htaccess

And so, for each file access out of that directory, there
are 4 additional file-system accesses, even if none of those
files are present. (Note that this would only be the case if
.htaccess files were enabled for /, which is not usually the
case.)

The second consideration is one of security. You are
permitting users to modify server configuration, which may
result in changes over which you have no control. Carefully
consider whether you want to give your users this privilege.''

- http://httpd.apache.org/docs/howto/htaccess.html
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #21
I talk about .htaccess because that it what most people have access, but if
you have access to Apache conf, it's just better.

Savut

"Tim Tyler" <ti*@tt1lock.org> wrote in message news:Hv********@bath.ac.uk...
Savut <we***@hotmail.com> wrote or quoted:
If someone can't use .htaccess because the hosting prohibit it, well I
suggest to change the hosting company because he miss a lot of features
that
an .htaccess file can do. :D


Use of ".htaccess" is *often* turned off - on grounds of performance and
security [1].

I can't see why should I instruct people to change their site hosting so
they can run my software - when there's no need for me to force them to
do so.

Lastly, .htaccess is an apache-specific feature. Apache is not the
only PHP server in existence - and I would prefer my software to be
portable.

[1] ".htaccess files, Apache Tutorial"

``There are two main reasons to avoid the use of .htaccess
files.

The first of these is performance. When AllowOverride is set
to allow the use of .htaccess files, Apache will look in
every directory for .htaccess files. Thus, permitting
.htaccess files causes a performance hit, whether or not you
actually even use them! Also, the .htaccess file is loaded
every time a document is requested.

Further note that Apache must look for .htaccess files in
all higher-level directories, in order to have a full
complement of directives that it must apply. (See section on
how directives are applied.) Thus, if a file is requested
out of a directory /www/htdocs/example, Apache must look for
the following files:

/.htaccess
/www/.htaccess
/www/htdocs/.htaccess
/www/htdocs/example/.htaccess

And so, for each file access out of that directory, there
are 4 additional file-system accesses, even if none of those
files are present. (Note that this would only be the case if
.htaccess files were enabled for /, which is not usually the
case.)

The second consideration is one of security. You are
permitting users to modify server configuration, which may
result in changes over which you have no control. Carefully
consider whether you want to give your users this privilege.''

- http://httpd.apache.org/docs/howto/htaccess.html
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.


Jul 17 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: R. Rajesh Jeba Anbiah | last post by:
Sometimes ago I started a thread <http://groups.google.com/groups?threadm=abc4d8b8.0404012208.76ebdba7%40posting.google.com> <Previous post> I'm supposed to hide the php extension in a file...
8
by: Pjotr Wedersteers | last post by:
I am new to J(ava)Script, use PHP a lot and consider moving some stuff for a project over to the client side. Problem is part of the PHP code is copyrighted and the author would not be happy to see...
5
by: Arnaud Legrand | last post by:
Hello, I have a question about portability and I have not found the answer in the FAQ. I have different modules to build. All of them have the same private part and a common public part (though...
7
by: Dennis | last post by:
I have a class named myclass that inheirits from "baseclass". There is a property of "baseclass" that I don't want exposed in the IDE. The MSDN documentation says" "A derived type can hide an...
19
by: Badr.ALmuzini | last post by:
hi,there how can i make php file extension hidden in the URL somthing like this (http://mail.google.com/mail/?view) Regard....
13
by: Matt | last post by:
Does anyone know how to hide the ASPX extension of web pages in ASP.Net 2.0? Thanks, Matt
6
by: 3338761 | last post by:
I'm a beginner programmer so bear with me if this seems very simple... I have a subform which I don't want to have displayed until the user has entered first name, last name, extension, and chose...
2
by: codexxx | last post by:
Hi,all I wanted to make a system so that in the browser php extension cant be seen. Though I have been able to make it by editing the .htaccess file but I want it such a way that if anyone type...
8
by: Frank Rizzo | last post by:
How come VS2008 does not show built-in extension methods for the string class? Like ToList() method, for instance.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.