i would like to set up a directory, lets say /home/testsite/httpdocs/

in this directory there will be lots of subdirectories etc. now, what i want is to be able to automatically select index.php REGARDLESS of what is requested.

if for example, someone requests (by typing into their browser)

www.mysite.com/chocolate or
www.mysite.com/covered or
www.mysite.com/porkchops

apache knows already to serve /home/testsite/httpdocs/index.php

thats problem one.

the second problem:

how do i get index.php to see what the url was, because index.php will be deciding what to do, based on what was requested.

    Stuff for that can be found in the $_SERVER[] array. Look it up in the manual, because there's way too much info there to copy into a post.

      ok, so i can find in there, stuff for me to solve problem two.... still leaves me problem one tho...

        Originally posted by stevesweetland
        ok, so i can find in there, stuff for me to solve problem two.... still leaves me problem one tho...

        No, that's in $_SERVER as well; your current location is described in (off the top of my head) at least three different ways, both relatively and absolutely.

          im either not getting what u mean, or im not explaining myself properly..

          soooo

          lets say i go to a website and type

          www.foobar.com/sausages.php or
          www.foobar.com/chips.php or
          www.foobar.com/mash or (no extension on purpose)
          www.foobar.com/oniongravy or (no extension on purpose)
          www.foobar.com/mushypeas.php

          i want apache to serve index.php, regardless of what is typed in (only for this folder)

          index.php reads what was requested (using the $_SERVER) vars, and decides wat to do, but there is no such file as sausages.php.

          that doesnt matter tho - as apache knows to serve index.php.. cause iv done a magical bit of server setting up to make it do that..

            what you're describing is similar to the apache mod_rewrite which I've never gotten to work properly. (mostly because I haven't needed to)

            but what it effectively does is makes url variables look like folder structure. e.g.

            www.foo.com?id=123&bar=foo

            would look like

            www.foo.com/123/foo

            There's tons of info on mod_rewrite out there, some on this site I believe. Google is your friend 😉

            Or, in some crazy roundabout way you could customise your 404 page to do what you want your index.php to do. So when someone requests a page that's not there the 404 can pick up the $_SERVER info and do the work or redirect them to the index.php

              10 months later
              Write a Reply...