【问题标题】:php and htaccess, url rewriting by mysql table id and other columnphp 和 htaccess,通过 mysql 表 id 和其他列重写 url
【发布时间】:2013-04-28 12:22:24
【问题描述】:

你好我的mysql表是这样的

[ID] [TITLE] [SEOLINK]
[1] [Test] [test]
[2] [Test 2] [test-2]

我的php url是这样的 example.com/index.php?id=2

如何htaccess重写,所以链接可以 example.com/page/test-2

谢谢。

【问题讨论】:

    标签: php mysql .htaccess


    【解决方案1】:

    首先,必须改变mysql的条件。

    $query = "select * from TABLE where ID = '".$_GET['id']."'";
    mysql_query($query);
    
    to 
    
    $query = "select * from TABLE where SEOLINK = '".$_GET['param']."'";
    mysql_query($query);
    

    现在,您可以在.htaccess 中使用RedirectRule。喜欢:

    RewriteRule ^page/(.*)$ http://example.com/index.php?param=$1 [NC]
    

    【讨论】:

      【解决方案2】:

      此重写规则将接受格式为 /page/this-is-my-page-title-123 的 URL,其中 123 是页面的 ID。

      它也将是 QueryString 感知的(这意味着您可以在末尾添加 ?param=value,这将被处理)

      RewriteEngine On
      RewriteRule ^page/[\w\-]+(\d)+ /index.php?id=$1 [L,QSA,NC]
      

      【讨论】:

        猜你喜欢
        • 2013-11-03
        • 1970-01-01
        • 2015-05-29
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 2013-06-23
        相关资源
        最近更新 更多