使用内部服务器错误重写工作URL

时间:2014-09-30 09:50:09

标签: php .htaccess mod-rewrite url-rewriting

我试图使用.htaccess进行网址重写,但问题是,当我点击链接时,它会在地址栏上显示url重写,但页面显示此错误内部服务器错误,我已打开我需要在我的wamp中打开必要的东西(LoadModule rewrite_module modules / mod_rewrite.so),所以我如何解决这个问题,下面我的代码是这些页面的index.php,venues.php(包含类),登陆.php(显示地址栏上的URL重写好,但显示内部服务器错误)和.htaccess。

index.php
include_once("venues.php");

$venue = new venues;

$thedate = $venue->listAllVenue();              

if (count($thedate)) {
    for ($i =0; $i < count($thedate); $i++) { 
        $id = $list[$i]['id'];
        <a href="<?php echo venues::theurl($list[$i]['id'], "venue"); ?>"><?php echo $list[$i]['venue_title']; ?></a>
    }

venues.php
class venues{
    function OneVenue($id, $point='id') {
        $query = "SELECT * FROM venues WHERE id = '".$id."'";
        $sql = mysql_query($query) or die (mysql_error());

        if ($sql) {
            $result = array();
            $row = mysql_fetch_array($sql);
            $result['id'] = $row['id'];
            $result['venue_title'] = $row['venue_title'];
            return $result;
        } else {
            return false;
        }
    }   

    function theurl($id, $point="", $type="") {
        if ($point == "venue") {
            $data = venues::OneVenue($id);
            $id = $data['id'];
            $thename = trim(strtolower($data['venue_title']));

            $urlLink = explode(" ", $thename);
            $sublink = implode("-", $urlLink);

            $result = URL."venue-details/".$id."/".$sublink."/";
        }
    return $result;
    }
}

landing.php
include_once("venues.php");
$venue = new venues;

if (isset($_REQUEST['id'])) {
    $id = $_REQUEST['id'];
    $pickvenue = $venue->OneVenue($id);
    echo $pickvenue['venue_title'];
}

.htaccess
RewriteEngine on
RewriteRule ^venues/([a-zA-Z)([0-9]+)/(.*?)/$ venue-details?id=$1


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

1 个答案:

答案 0 :(得分:0)

您的索引页已损坏

你的代码

include_once("venues.php");
$venue = new venues;

$thedate = $venue->listAllVenue();              
if (count($thedate)) {
for ($i =0; $i < count($thedate); $i++) { 
$id = $list[$i]['id'];
<a href="<?php echo venues::theurl($list[$i]['id'], "venue"); ?>"><?php echo $list[$i]['venue_title']; ?></a>
}

为何无效

if (count($thedate)) { // <- has no closing bracket
    for ($i =0; $i < count($thedate); $i++) { 
        $id = $list[$i]['id'];
        // the line below just starts hmtl output with no closing php tags
        <a href="<?php echo venues::theurl($list[$i]['id'], "venue"); ?>"><?php echo $list[$i]['venue_title']; ?></a>
    }

将其更改为以下内容并重试;

include_once("venues.php");
$venue = new venues;

$thedate = $venue->listAllVenue();
if (count($thedate))
{
    for ($i =0; $i < count($thedate); $i++)
    { 
        $id = $list[$i]['id'];
        ?>
        <a href="<?php echo venues::theurl($list[$i]['id'], 'venue'); ?>"><?php echo $list[$i]['venue_title']; ?></a>
        <?php
    }
}