我正试图用.htaccess进行url重写,这是有效的,但问题是,当我点击链接时,它在地址栏上很好地显示了url重写,但页面显示了这个错误Internal Server error,我已经打开了我需要在我的wamp中打开的必要的东西,比如(LoadModule rewrite_module/mod_rewrite.so),所以我该如何解决下面的问题下面的代码包含以下页面:index.php、venues.php(包含类)、landing.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
您的索引页已损坏
您的代码
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
}
}