如何根据用户请求用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}::$1 ^(/.+)(.+)::'2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

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