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

PHP files without extension

I know how to set Apache to send files with any extension to PHP before
sending a response. Is there a way to do so for files with no extension
whatsoever? I don't want *all* files to be parsed by PHP, but only those
without extension (and, of course, with some selected extensions).

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #1
12 13316
Berislav Lopac <be************@dimedia.hr> wrote:
I know how to set Apache to send files with any extension to PHP before
sending a response. Is there a way to do so for files with no extension
whatsoever? I don't want *all* files to be parsed by PHP, but only those
without extension (and, of course, with some selected extensions).


Maybe you should take a look at MultiViews. This lets you write URLs
without extension and let Apache guess what file actually should be
used. http://example.com/foo will for example be evaluated to
http://example.com/foo.php if it exists or http://example.com/foo.html
instead...

--

Daniel Tryba

Jul 17 '05 #2
On Tue, 31 Aug 2004 12:03:12 +0200, "Berislav Lopac"
<be************@dimedia.hr> wrote:
I know how to set Apache to send files with any extension to PHP before
sending a response. Is there a way to do so for files with no extension
whatsoever? I don't want *all* files to be parsed by PHP, but only those
without extension (and, of course, with some selected extensions).

Berislav

If this is on a Unix box, just dropping the extension and providing you
have '<?php' at the top, the files should be parsed as PHP files.

Unlike windoze, Unix doesn't stupidly rely on the file extension to tell
the OS what the file is.

The other way would be to use mod_rewrite in Apache:
RewriteRule /^(files|you|wish|to|parse|as|php)$ /$1.php [L]
You'd save the files as foo.php etc, but access to '/foo' would then
read the 'foo.php' file without requiring the .php extension.
HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #3
Ian.H wrote:

If this is on a Unix box, just dropping the extension and providing
you have '<?php' at the top, the files should be parsed as PHP files.
It doesn't work -- as I expected, it displays the PHP code. This is on a
Fedora box with Apache 1.3.29 -- perhaps this works in Apache 2?
The other way would be to use mod_rewrite in Apache:
RewriteRule /^(files|you|wish|to|parse|as|php)$ /$1.php [L]
You'd save the files as foo.php etc, but access to '/foo' would then
read the 'foo.php' file without requiring the .php extension.
HTH =)


It does help, but is there a way to do it via an AddType statement in the
httpd.conf, which AFAIK itself uses mod_rewrite?

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #4
Berislav Lopac wrote:
the httpd.conf, which AFAIK itself uses mod_rewrite?


Ooops, it turns out I don't know. It uses mod_mime, not mod_rewrite.

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #5
On Tue, 31 Aug 2004 13:23:52 +0200, "Berislav Lopac"
<be************@dimedia.hr> wrote:
Ian.H wrote:

If this is on a Unix box, just dropping the extension and providing
you have '<?php' at the top, the files should be parsed as PHP files.


It doesn't work -- as I expected, it displays the PHP code. This is on a
Fedora box with Apache 1.3.29 -- perhaps this works in Apache 2?

Never used Apache2.. but you're right, it doesn't work for me either. I
must have confused that with something else a long time ago. Apologies
=)

The other way would be to use mod_rewrite in Apache:
RewriteRule /^(files|you|wish|to|parse|as|php)$ /$1.php [L]
You'd save the files as foo.php etc, but access to '/foo' would then
read the 'foo.php' file without requiring the .php extension.
HTH =)


It does help, but is there a way to do it via an AddType statement in the
httpd.conf, which AFAIK itself uses mod_rewrite?

Berislav

You could use AddType statements in vhost sections in httpd.conf or
within .htaccess files per-dir if preferred:
<Files foo>
ForceType application/x-httpd-php
</Files>
etc etc.. the just save the file as 'foo' and all should be sweet =)

HTH more.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #6
Ian.H wrote:
You could use AddType statements in vhost sections in httpd.conf or
within .htaccess files per-dir if preferred:
<Files foo>
ForceType application/x-httpd-php
</Files>
etc etc.. the just save the file as 'foo' and all should be sweet =)

HTH more.


Nope, sorry. It still just shows the code...

I'm playing with aliases a bit, but I would still like to have a generic
parse via PHP be applied to filenames without extensions, if possible.

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #7
Ian.H wrote:
If this is on a Unix box, just dropping the extension and providing
you have '<?php' at the top, the files should be parsed as PHP files.


I have just discovered the strangest thing: if there is a file named foo.php
on the server, just calling /foo works!

E.g. http://localhost/foo = http://localhost/foo.php

Confused, but happy,

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #8
On Tue, 31 Aug 2004 10:39:25 +0000, Ian.H wrote:
If this is on a Unix box, just dropping the extension and providing you
have '<?php' at the top, the files should be parsed as PHP files.

Unlike windoze, Unix doesn't stupidly rely on the file extension to tell
the OS what the file is.


While the second part is true, the first part is not -- quite. Since
Apache is doing the parsing and not your Unix box, you *do* have to tell
Apache how to parse the files if you want them to be seen by the PHP
engine.

So I think that, as far as web serving goes, a similarly configured Apache
server on *either* Unix or Windows will work the same way. Because the OS
is not doing the parsing -- Apache is.

Not sure how you can configure PHP parsing for files with no extension,
but I would wager it can be done.

--
Jeffrey D. Silverman | je**********@jhu.edu **
Website | http://www.newtnotes.com

(** Drop "pants" to reply by email)

Jul 17 '05 #9
On Tue, 31 Aug 2004 13:23:52 +0200, "Berislav Lopac"
<be************@dimedia.hr> wrote:
It does help, but is there a way to do it via an AddType statement in the
httpd.conf,


Untested, but how about something like

<FilesMatch '^[^.]+$'>
ForceType application/x-httpd-php
</FilesMatch>

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

"Berislav Lopac" <be************@dimedia.hr> сообщил/сообщила в новостях
следующее: news:ch**********@ls219.htnet.hr...
Ian.H wrote:
If this is on a Unix box, just dropping the extension and providing
you have '<?php' at the top, the files should be parsed as PHP files.
I have just discovered the strangest thing: if there is a file named

foo.php on the server, just calling /foo works!

E.g. http://localhost/foo = http://localhost/foo.php

Confused, but happy,

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.

I have <quote>The requested URL /test was not found on this server.</quote>
though there is test.php

Jul 17 '05 #11
.oO(Berislav Lopac)
I have just discovered the strangest thing: if there is a file named foo.php
on the server, just calling /foo works!

E.g. http://localhost/foo = http://localhost/foo.php

Confused, but happy,


Nothing strange, this is called MultiViews. See the Apache manual entry
on "Content negotiation" for details.

<http://httpd.apache.org/docs/content-negotiation.html>

Micha
Jul 17 '05 #12
Varavva Yevgen aka xa4anypu wrote:
I have <quote>The requested URL /test was not found on this server.</quote>
though there is test.php


'Note that Options All does not set MultiViews; you have to
ask for it by name.'

http://httpd.apache.org/docs/content-negotiation.html

Since it seems Berislav doesn't want URI suffixes, and isn't
concerned about file extensions, I second Daniel's
suggestion of considering MultiViews.

--
Jock
Jul 17 '05 #13

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

Similar topics

3
by: John Field | last post by:
Hello, Is it possible to exclude certain files in a wx.FileDialog, so that the user won't see them and can't select them with the mouse in de File open window? I was thinking of somehow...
6
by: J. Shrimp, Jr. | last post by:
Following code exports tables as text files: For Each tdf In db.TableDefs StrTblName = tdf.Name Me.txtProgName = StrTblName Me.txtProgName.Requery tblAtt = tdf.Attributes moddate =...
3
by: James | last post by:
Hi, I'm importing some csv files with this code /// start of code snippet int iPos = strFileName.LastIndexOf(@"\"); string strPath = strFileName.Substring(0,iPos); string strSelect =...
2
by: Kenneth Myhra | last post by:
Hi all, We are trying to make an ISAPI Filter, in .NET by implementing the IHttpModule interface, that will authorize the request for certain binary file types (GET), this is working fine. But we...
1
by: Aaron via DotNetMonster.com | last post by:
I am testing for several file types in a directory by creating an array of masks and for each mask in the array, I execute a GetFiles. My issue is that the VB code: ...
5
by: Amjad | last post by:
Hi, I want to write a For loop that will put file names of extensions (*.txt and *.csv) in an array. I had it work fine for one extension, and I need help making it work for two extensions. My...
13
by: kbperry | last post by:
Hi all, Background: I need some help. I am trying to streamline a process for one of our technical writers. He is using Perforce (version control system), and is constantly changing his word...
1
by: Kesavan | last post by:
I install apache2 in /usr/local/apache2 and install php5 by ./configure --with-apxs2=/usr/local/apache2/bin/ apxs PHP is successfully installed in my system. But now my .php files inside...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.