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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探