views:

31

answers:

2

For example, to access a page in my search folder, I have to write:

mywebsite.tld/search/searchJob.php

I don't want users to have to write down folder structure and whatnot. What can I do to change this?

OR, is there a better way to organize my files? Because I'm only two pages in and I decided to move some files and got lost in the heirarchy (that's why I moved them like in the picture).

+2  A: 

Three main options:

  1. You can use Apache's mod_rewrite.
  2. You can hack your own URL handler, by parsing $_SERVER['REQUEST_URI'].

    if ($_SERVER['REQUEST_URI'] == "/jobs") {
        require_once("search/searchJob.php");
    }
    
  3. Use a web framework that properly handles URLs for you.

Fragsworth
Which one uses less resources/easier to maintain? Do you have a tutorial somewhere where I could learn? :)
Serg
+1  A: 

With the Apache web server, you could use mod_rewrite to beautify the URLs so that users don't have to type in everything. For example, users open mywebsite.tld/search/ and the request will be processed by mywebsite.tld/search/searchJob.php without the user noticing it. This has another big advantage: You can organize the files as you want, and change the file names arbitrarily - you'll only have to change the URL mapping when you move or rename a PHP file.

As an aside: Users will almost never type in a full URL, normal users click through the main page or use enhanced address bars (like the Firefox address bar which shows history items) to open a web page.

AndiDog