duanjing7298 2013-04-15 16:49
浏览 54

Apache RewriteMap无法正常工作

I'm trying to rewrite some of my URLs using an apache RewriteMap.

I'd like to transform

www.mywebsite.com/?p=category&id=xxxx

in

www.mywebsite.com/category/channel/program/personnality

I use the id in a php script to retrieve the necessary variables from the db.

So far it isn't working, and after countless hours of research, I thought I would ask for a little help.

I shamelessly re-used some of the config provided here

Here's my httpd.conf

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteMap redirects prg:/var/www/redirects/redirects.php
RewriteCond ${redirects:%{HTTP_HOST}%{REQUEST_URI}} !^GOOD$
RewriteRule ^/(.*)$ ${redirects:%{HTTP_HOST}%{REQUEST_URI}} [R]
</IfModule>

and my redirects.php script, working properly on its own

#!/usr/bin/php
<?php
set_time_limit (0);
$input = fopen ('php://stdin', 'r');
$output = fopen ('php://stdout', 'w');

while (1) {
$original = strtolower (trim (fgets ($input)));

$request = array();
if (preg_match("/[0-9]+/", $original, $request) == 0)
fwrite ($output, "GOOD
");

$con = mysqli_connect("localhost","user","password","db");

if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$r = mysqli_query($con, "SELECT media.me_libelle, projet.pro_libelle,  personnalite.per_prenom,personnalite.per_nom FROM image, media, projet, image_personnalite,  personnalite
                              WHERE image_personnalite.per_id=personnalite.per_id and image.pro_id=projet.pro_id and projet.me_id=media.me_id  and image.img_id=".$request[0]." and image_personnalite.img_id=".$request[0]);


if ($r = mysqli_fetch_array($r))
{
$i = 0;
while (isset($r[$i]) && !empty($r[$i]))
  {
    $r[$i] = preg_replace("/\s/", "-", $r[$i]);
    $i++;
  }
$url= strtolower("www.mywebsite.com/"."category/".$r[0]."/".$r[1]."/".$r[2]."-".$r[3]);
}

mysqli_close($con);
fwrite ($output, "http://".$url."
");
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗