开发者

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

开发者 https://www.devze.com 2022-12-25 03:09 出处:网络
For example, to access a开发者_开发知识库 page in my search folder, I have to write: mywebsite.tld/search/searchJob.php

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

精彩评论

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

关注公众号