dongrandi8411 2014-10-28 20:15
浏览 41

php SEO urls通过关键字和mysql查询重写

First, in .htaccess file i put this lines

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)?$ index.php?key=$1 [L]

I got also table in MySQL

| aliasID |     query     | keyword |
--------------------------------------
|    1    | site=articles | articles |

Now in index.php i got

    if(isset($_GET['key'])) $key = $_GET['key'];
    else $key = '';

    if($key) 
    { 

        $invalide = array('\\','/','/\/',':','.');
        $key = str_replace($invalide,' ',$key);

        $checkiskey=mysql_fetch_array(safe_query("SELECT * FROM seoaliasy WHERE keyword='".$key."'"));

        if($checkiskey) {

            // here missing code

        } else { echo '404'; }

    } else {

    echo 'main page';

    }

Now i want to know what code i need to put in "//here missing code" place that include content of page called from MySQL query of MySQL column.

The properly address of site is www.example.com/index.php?site=articles (if this was entered in address bar of internet browser the page was appears corectly)... but i need that the same page must be included after if in address bar i put http://www.example.com/articles (so query [site=articles] from correctly address was converted to key from [keyword] column in MySQL)

Simple, i looking solution for simple SEO URL rewriting based on MySQL table with "queries" and "keywords".

  • 写回答

1条回答 默认 最新

  • dongyao1895 2014-10-28 20:32
    关注

    I am not sure from where you want to access the data. However You can call content of any page in PHP by using CURL

        $ch = curl_init("YOUR_PAGE_URL");
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);       
        curl_close($ch);
        echo $output;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘