0

Actually, I have created an html page as a master page, I want to change the contents of body part by accessing database. As for example, If I have created a table with columns

pages_name, page_contents, page_id
about         somthing        1
services      somthing        2

Here, I am trying to do that If I change contents of my page for "about" then url will automatically change from "www.anything.com" to "www.anything.com/about" without creating another html file for "about".

How will change my url according to database content?

4

2 回答 2

2

你应该使用htaccess,mod rewrite

 Options +FollowSymLinks
 RewriteEngine On

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . index.php [L]

然后像这样路由你的页面

$pages = array('register' => '/view/pages/register.php','something' => '/view/pages/some.php');

分解链接以获取数组中的名称

$findPage = explode('/', $_SERVER['REQUEST_URI']);

如果链接是 www.homepage.com/register/ 爆炸结果将被注册 ($findPage[1])

查找当前页面

if(@array_key_exists($findPage[1], $allowed)) {

    include($allowed[$findPage[1]]); // if page found

}else{

    include($allowed['default']); // deafulat home page

}

类似的东西。这适用于 ngix

于 2013-07-20T20:09:25.200 回答
0

使用单个 html 模板并在 URL 中使用 get 变量来查询不同的页面:

www.anything.com?pageid=3

那么如果你想要更多的用户和 seo 友好的 URL 用户 apache mod_rewrite 来定义重定向。

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

于 2013-07-20T20:08:48.660 回答