【问题标题】:working url rewriting with Internal Server Error使用内部服务器错误重写工作 url
【发布时间】:2014-09-30 18:40:39
【问题描述】:

我正在尝试使用 .htaccess 进行 url 重写,但问题是,当我单击链接时,它会在地址栏上显示 url 重写,但页面显示此错误 Internal Server Error 并且我已打开我需要在我的 wamp 中打开必要的东西,比如(LoadModule rewrite_module modules/mod_rewrite.so)所以我该如何解决这个问题是我下面的代码与这些页面 index.php、venues.php(包含类)、登陆.php(在地址栏上显示 url rewiting 很好,但显示 Internal Server Error)和 .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

【问题讨论】:

  • 在venues.php 中,您在$result = URL."venue-details/".$id."/".$sublink."/"; 行中使用了全局变量URL 您是否在某处明确设置了此全局变量?它应该看起来像 define('URL', 'www.mysite.com'); 或类似的东西。
  • 同样在同一个文件中,您正在执行 sql 查询(顺便说一下,这很容易受到 sql 注入的影响),但我没有看到任何连接到数据库函数。

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


【解决方案1】:

您的索引页已损坏

你的代码

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
    }
}

【讨论】:

  • 仍然给我同样的错误(内部服务器错误)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-20
  • 2014-06-29
  • 1970-01-01
相关资源
最近更新 更多