【问题标题】:create html pages dynamically with proper url使用正确的 url 动态创建 html 页面
【发布时间】:2014-11-26 07:53:06
【问题描述】:

我想使用 php 脚本(例如:category.php)动态创建网页,该脚本采用变量 'category' 并执行 mysql 查询以从服务器获取数据并创建网页。

category.php

 < ? php
    include_once("php_includes/db_conx.php");


    $sql = "SELECT * FROM PRODUCTS WHERE CATEGORY = 'CLOTHING' ";
    $result = $db_conx->query($sql);

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {

         /*GENERATE SOME WEBPAGE*/


         }
    }

    ? >

因此,当用户单击“/category/clothing”链接时,它应该从此链接中选择变量值(category = 'clothing')并动态生成地址为“www.example.com/category/clothing”的网页" 而不是像 "www.example.com/category/?category=clothing"

我要避免的是一个带有“?”的网址和'='

所以我想实现两件事:

  1. 单个 php 文件通过从“/category/clothing”等链接中获取值来动态生成页面
  2. 新网页的Url应该是简单正确的“www.example.com/category/clothing”(当然应该和点击的链接一样),而不是像“www.example.com/category/?category” =服装”

有人可以编写一个示例 php 或 js 脚本来实现这一点或为我指明正确的方向(以防万一很简单)

【问题讨论】:

  • 您要查找的是 .htaccess 文件中的 mod_rewrite -wettone.com/code/clean-urls
  • 你知道 mod_rewrite 使用 htaccess 吗?
  • 我认为 mod_rewrite 会完成这项工作。在使用 url 发出 ajax 请求时,它是否也可以类似地工作?

标签: javascript php


【解决方案1】:

PHP 自己无法做到这一点。您将需要一个名为 mod rewrite 的 .htaccess apache 模块。这是一个如何制作漂亮网址的教程。

http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-15
    • 2014-03-19
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 2010-10-10
    相关资源
    最近更新 更多