Website Structure

后端 未结 9 795
无人及你
无人及你 2021-02-04 19:43

I\'m pretty new to php and i\'m trying to decide the best way to organize the pages and, using PHP, deliver them. The two (basic) ideas I\'ve had are:

  • A bunch o

9条回答
  •  花落未央
    2021-02-04 20:14

    I've gone in both directions before, and though they both have pros and cons I lean toward your second option, the single main page that contains the layout. This is similar to how master pages work in desktop publishing applications, and ASP.NET has a nice implementation of this idea - not that I'm saying you should switch technologies.

    However, if you do go this route, use mod_rewrite to get your paths into the PHP master page, rather than querystrings in your URLs. Your .htaccess file should contain something like:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [S=1]
    RewriteRule ^(.*)$ /index.php?path=$1 [QSA]
    

    This basically says if the file they ask for didn't exist, instead of giving a 404 error hand off processing to index.php with the URL path in a querystring variable. So "http://example.com/path/to/page" ends up hitting index.php with $_GET['path'] set to "/path/to/page". From there you can pull content from a database, a flat file, or what have you. You can also choose different templates based on the path requested.

提交回复
热议问题