473,406 Members | 2,439 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,406 software developers and data experts.

[Revisited] Hiding PHP extension

Sometimes ago I started a thread
<http://groups.google.com/groups?threadm=abc4d8b8.0404012208.76ebdba7%40post ing.google.com>

<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>

At that time I was getting many answers. But, recently I have found
another suggestion in the 'net:

<FilesMatch "^([^\.]+)$">
ForceType application/x-httpd-php
</FilesMatch>

Source: http://forum.textpattern.com/viewtopic.php?id=184 and
http://www.devarticles.com/c/a/Apach...r-Page-URLs/1/

Any comments or any better ideas? TIA

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #1
6 2523
R. Rajesh Jeba Anbiah wrote:
Sometimes ago I started a thread
<http://groups.google.com/groups?threadm=abc4d8b8.0404012208.76ebdba7%40post ing.google.com>

<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>
For mod_rewrite, if you want to have a URI of /foo do NOT have a file
called foo.php, or it will use that instead (depending on the Apache
setup). What you can do, however is to do something like:

RewriteRule ^foo/?$ foo_process_request.php

That way, you have your URI of /foo as well as a filename that may be
more specific to its task "foo_process_request.php"

Also, one of the rules I use look like:

RewriteRule ^([^/]+)(/([^/]+))?/?$ x.php?s=$1&p=$3 [L,NS,QSA]

That allows me to have URIs like:

/section
/section/
/section/page
/section/page/

That translate to requests like:

x.php?s=section&p=
x.php?s=section&p=
x.php?s=section&p=page
x.php?s=section&p=page

Then in x.php, you can call the correct include files based on the _GET
parameters.
At that time I was getting many answers. But, recently I have found
another suggestion in the 'net:

<FilesMatch "^([^\.]+)$">
ForceType application/x-httpd-php
</FilesMatch>
That forces all files without an extension to be a PHP file. Don't know
xactly what would happen if your request was a directory without the
trailing slash... One other thing to think of is what if you had a
request like /foo/ what happens then?
Source: http://forum.textpattern.com/viewtopic.php?id=184 and
http://www.devarticles.com/c/a/Apach...r-Page-URLs/1/

Any comments or any better ideas? TIA


I don't know what Zeus or IIS support is for FilesMathc, but I do know
that they both support mod_rewrite syntax (IIS uses something called
ISAPI_rewrite that would need to be installed). Because of this, I
continue to use mod_rewrite for portability's sake.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Jul 17 '05 #2
> At that time I was getting many answers. But, recently I have found
another suggestion in the 'net:

<FilesMatch "^([^\.]+)$">
ForceType application/x-httpd-php
</FilesMatch>


If you want to save yourself some time and a headache AND you don't mind
having all files under a directory read in as PHP files, you can create an
..htaccess file with the following line included:

ForceType application/x-httpd-php

Now, any file you create in that directory, whether or not it has an
extension or not, will be parsed as php code.

____________________________________
Wil Moore III, MCP | Integrations Specialist
Jul 17 '05 #3
Justin Koivisto <sp**@koivi.com> wrote in message news:<aH******************@news7.onvoy.net>...
R. Rajesh Jeba Anbiah wrote:
Sometimes ago I started a thread
<http://groups.google.com/groups?threadm=abc4d8b8.0404012208.76ebdba7%40post ing.google.com> <snip>
Also, one of the rules I use look like:

RewriteRule ^([^/]+)(/([^/]+))?/?$ x.php?s=$1&p=$3 [L,NS,QSA]

That allows me to have URIs like:

/section
/section/
/section/page
/section/page/

That translate to requests like:

x.php?s=section&p=
x.php?s=section&p=
x.php?s=section&p=page
x.php?s=section&p=page

Then in x.php, you can call the correct include files based on the _GET
parameters.
At that time I was getting many answers. But, recently I have found
another suggestion in the 'net:

<FilesMatch "^([^\.]+)$">
ForceType application/x-httpd-php
</FilesMatch>


That forces all files without an extension to be a PHP file. Don't know
xactly what would happen if your request was a directory without the
trailing slash... One other thing to think of is what if you had a
request like /foo/ what happens then?


Thanks for your comments. Yes, I understand the situation you're
referring. And if I'm right, there won't be any problem with such
directory requests.
Source: http://forum.textpattern.com/viewtopic.php?id=184 and
http://www.devarticles.com/c/a/Apach...r-Page-URLs/1/

Any comments or any better ideas? TIA


I don't know what Zeus or IIS support is for FilesMathc, but I do know
that they both support mod_rewrite syntax (IIS uses something called
ISAPI_rewrite that would need to be installed). Because of this, I
continue to use mod_rewrite for portability's sake.


It seems you're advocating mod_rewrite. Sometimes ago when I was
digging on this subject, I found a article which hinted performance
issue with mod_rewrite (but not sure really). The major problem (for
me) I have found with mod_rewrite is hardcoding of links and or a
mechanism to handle links as $_SERVER['PHP_SELF'] won't work.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4
<la*******@hotmail.com> wrote in message news:<10*************@corp.supernews.com>...
At that time I was getting many answers. But, recently I have found
another suggestion in the 'net:

<FilesMatch "^([^\.]+)$">
ForceType application/x-httpd-php
</FilesMatch>


If you want to save yourself some time and a headache AND you don't mind
having all files under a directory read in as PHP files, you can create an
.htaccess file with the following line included:

ForceType application/x-httpd-php

Now, any file you create in that directory, whether or not it has an
extension or not, will be parsed as php code.


Thanks for your comments. I think, that will be much overhead for
the PHP parser as it will result in parsing all files (even .jpg,
..gif, .html, etc). Anyway, are you hinting that restricting the
parsing level with <FilesMatch "^([^\.]+)$"> is overhead?

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5
R. Rajesh Jeba Anbiah wrote:
Justin Koivisto <sp**@koivi.com> wrote in message news:<aH******************@news7.onvoy.net>...
R. Rajesh Jeba Anbiah wrote:
Sometimes ago I started a thread
<http://groups.google.com/groups?threadm=abc4d8b8.0404012208.76ebdba7%40post ing.google.com>

<snip>
Also, one of the rules I use look like:

RewriteRule ^([^/]+)(/([^/]+))?/?$ x.php?s=$1&p=$3 [L,NS,QSA]

That allows me to have URIs like:

/section
/section/
/section/page
/section/page/

That translate to requests like:

x.php?s=section&p=
x.php?s=section&p=
x.php?s=section&p=page
x.php?s=section&p=page

Then in x.php, you can call the correct include files based on the _GET
parameters.


It seems you're advocating mod_rewrite.


Hmm... I guess I am. ;)
Sometimes ago when I was
digging on this subject, I found a article which hinted performance
issue with mod_rewrite (but not sure really).
IME, the performance hit due to mod_rewrite is less than trying to do
the same thing with PHP, therefore, I don't worry about it. They key is
to get your rules written in a way where they aren't wasting extra
resources. (The use of RewriteCond and the flags L and NS are nice
little gems.)
The major problem (for
me) I have found with mod_rewrite is hardcoding of links and or a
mechanism to handle links as $_SERVER['PHP_SELF'] won't work.


I've ditched $_SERVER['PHP_SELF'] altogether quite a while agoin favor
of $_SERVER['REQUEST_URI']. I just remove trailing slashes and query
strings via:

$_SERVER['REQUEST_URI']=preg_replace('/\?.*/','',$_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI']=preg_replace('/\/$/','',$_SERVER['REQUEST_URI']);

Then when I link or post a form, I'll use something like:

<form action="<?php echo $_SERVER['REQUEST_URI'] ?>/">

Of course, the other problem you may come across with mod_rewrite is
relative paths to images and other files. I take care of this through a
config.ini entry called "site_path" that may contain something like ""
or "/~myusername" Then all my images and anchor tags look similar to:

<img src="<?php echo $CFG['site_path'] ?>/images/img1.png">

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Jul 17 '05 #6
Justin Koivisto <sp**@koivi.com> wrote in message news:<kC******************@news7.onvoy.net>...
R. Rajesh Jeba Anbiah wrote:

Sometimes ago I started a thread
<http://groups.google.com/groups?threadm=abc4d8b8.0404012208.76ebdba7%40post ing.google.com>

<snip>
It seems you're advocating mod_rewrite.


Hmm... I guess I am. ;)
Sometimes ago when I was
digging on this subject, I found a article which hinted performance
issue with mod_rewrite (but not sure really).


IME, the performance hit due to mod_rewrite is less than trying to do
the same thing with PHP, therefore, I don't worry about it. They key is
to get your rules written in a way where they aren't wasting extra
resources. (The use of RewriteCond and the flags L and NS are nice
little gems.)
The major problem (for
me) I have found with mod_rewrite is hardcoding of links and or a
mechanism to handle links as $_SERVER['PHP_SELF'] won't work.


I've ditched $_SERVER['PHP_SELF'] altogether quite a while agoin favor
of $_SERVER['REQUEST_URI']. I just remove trailing slashes and query
strings via:

$_SERVER['REQUEST_URI']=preg_replace('/\?.*/','',$_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI']=preg_replace('/\/$/','',$_SERVER['REQUEST_URI']);

Then when I link or post a form, I'll use something like:

<form action="<?php echo $_SERVER['REQUEST_URI'] ?>/">

Of course, the other problem you may come across with mod_rewrite is
relative paths to images and other files. I take care of this through a
config.ini entry called "site_path" that may contain something like ""
or "/~myusername" Then all my images and anchor tags look similar to:

<img src="<?php echo $CFG['site_path'] ?>/images/img1.png">


Thanks Justin for your wonderful explanations. Now, I'm very
much convinced about mod_rewrite :-) Thanks a lot.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #7

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

Similar topics

21
by: R. Rajesh Jeba Anbiah | last post by:
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...
21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
26
by: djw | last post by:
Hi, Folks- I have a question regarding the "proper" use of try: finally:... Consider some code like this: d = Device.open() try: d.someMethodThatCanRaiseError(...) if SomeCondition: raise...
12
by: Kay Schluehr | last post by:
Hi all, thanks for Your attention ! I think my proposal was more in mind of Rons modified exec than Pythons lambda. When George proposed his unpacking behavoir for list-comps as a pack of...
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...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.