开发者

I want to better organize my website files, but I can access the .php files using the folder hierarchy. How can I override that?

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 hierarchy (that's why I moved them like in the picture).


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜