PHP files without extension

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Berislav Lopac

    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.


  • Daniel Tryba

    #2
    Re: PHP files without extension

    Berislav Lopac <berislav.lopac @dimedia.hr> wrote:[color=blue]
    > 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).[/color]

    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

    Comment

    • Ian.H

      #3
      Re: PHP files without extension

      On Tue, 31 Aug 2004 12:03:12 +0200, "Berislav Lopac"
      <berislav.lopac @dimedia.hr> wrote:
      [color=blue]
      >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[/color]


      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|wis h|to|parse|as|p hp)$ /$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

      Comment

      • Berislav Lopac

        #4
        Re: PHP files without extension

        Ian.H wrote:[color=blue]
        >
        > 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.[/color]

        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?
        [color=blue]
        > The other way would be to use mod_rewrite in Apache:
        >
        >
        > RewriteRule /^(files|you|wis h|to|parse|as|p hp)$ /$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 =)[/color]

        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.


        Comment

        • Berislav Lopac

          #5
          Re: PHP files without extension

          Berislav Lopac wrote:[color=blue]
          > the httpd.conf, which AFAIK itself uses mod_rewrite?[/color]

          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.


          Comment

          • Ian.H

            #6
            Re: PHP files without extension

            On Tue, 31 Aug 2004 13:23:52 +0200, "Berislav Lopac"
            <berislav.lopac @dimedia.hr> wrote:
            [color=blue]
            >Ian.H wrote:[color=green]
            >>
            >> 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.[/color]
            >
            >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?[/color]


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

            [color=blue][color=green]
            >> The other way would be to use mod_rewrite in Apache:
            >>
            >>
            >> RewriteRule /^(files|you|wis h|to|parse|as|p hp)$ /$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 =)[/color]
            >
            >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[/color]


            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

            Comment

            • Berislav Lopac

              #7
              Re: PHP files without extension

              Ian.H wrote:[color=blue]
              > 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.[/color]

              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.


              Comment

              • Berislav Lopac

                #8
                Re: PHP files without extension

                Ian.H wrote:[color=blue]
                > 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.[/color]

                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.


                Comment

                • Jeffrey Silverman

                  #9
                  Re: PHP files without extension

                  On Tue, 31 Aug 2004 10:39:25 +0000, Ian.H wrote:
                  [color=blue]
                  > 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.[/color]

                  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 | jeffreyPANTS@jh u.edu **
                  Website | http://www.newtnotes.com

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

                  Comment

                  • Andy Hassall

                    #10
                    Re: PHP files without extension

                    On Tue, 31 Aug 2004 13:23:52 +0200, "Berislav Lopac"
                    <berislav.lopac @dimedia.hr> wrote:
                    [color=blue]
                    >It does help, but is there a way to do it via an AddType statement in the
                    >httpd.conf,[/color]

                    Untested, but how about something like

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

                    --
                    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                    Comment

                    • Varavva Yevgen aka xa4anypu

                      #11
                      Re: PHP files without extension


                      "Berislav Lopac" <berislav.lopac @dimedia.hr> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
                      ÓÌÅÄÕÀÝÅÅ: news:ch1vci$7nc $1@ls219.htnet. hr...[color=blue]
                      > Ian.H wrote:[color=green]
                      > > 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.[/color]
                      >
                      > I have just discovered the strangest thing: if there is a file named[/color]
                      foo.php[color=blue]
                      > 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.
                      >
                      >[/color]
                      I have <quote>The requested URL /test was not found on this server.</quote>
                      though there is test.php





                      Comment

                      • Michael Fesser

                        #12
                        Re: PHP files without extension

                        .oO(Berislav Lopac)
                        [color=blue]
                        >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,[/color]

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

                        <http://httpd.apache.or g/docs/content-negotiation.htm l>

                        Micha

                        Comment

                        • John Dunlop

                          #13
                          Re: PHP files without extension

                          Varavva Yevgen aka xa4anypu wrote:
                          [color=blue]
                          > I have <quote>The requested URL /test was not found on this server.</quote>
                          > though there is test.php[/color]

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



                          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

                          Comment

                          Working...