如何根据用户请求创建带有 php 的子页面?

How to create sub pages with php on user request?

如果我的网站 url 类似于 someUrl.com 并且注册用户想要向我的网站添加文章,我想创建一个子页面 php:

类似于 someUrl.com/someSubPage

所以我的问题是:我应该使用 php 在服务器上创建一个新文件,还是应该将文章中的数据保存在数据库中并在每次用户请求时生成该文件?如果我选择第二个,那么 url (someUrl.com/someSubPage) 呢?这还能有一个url吗?

提前谢谢你!:D

编辑: 好的数据库似乎是更好的方法。但是搜索引擎怎么样?我可以在没有框架的情况下做到这一点吗?

是的,没有框架也可以。但是您可能会考虑使用 CodeIgniter,因为它非常容易安装和学习,而且重量不大。如果你想在没有的情况下这样做:你必须创建一个包含以下内容的 .htaccess 文件:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]


# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}:: ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

如果在文件系统中找不到该文件,将加载页面 index.php。您可以使用 $_SERVER['REQUEST_URI'] 获取请求的页面。