htaccess,用户友好的url,在某些文件中出错

时间:2013-07-09 12:55:03

标签: .htaccess url friendly-url

我想制作一些用户友好的网址,在这里发现了很多文章和问题,但我仍然有问题。该示例的目标是编写一些“文章”,并在show.php中打开后成为用户友好的URL

这是我的文件

在htdocs中我有'。set'文件夹:.htaccess,db.php,write.php,show.php。 db.php:

<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "test";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die();
mysql_select_db($mysql_database, $bd) or die();

show.php:

<?php
include('db.php'); 
if( isset( $_GET['url'] ) ) {  
    $sql=mysql_query("select title,body from blog where url='$url'");
    $count=mysql_num_rows($sql);
    $row=mysql_fetch_array($sql);
    $title=$row['title'];
    $body=$row['body'];
} 
?>
<!DOCTYPE html> 
<html> 
<body> 
    <div> <?php if( $count > 0 ) { echo "<h1>$title</h1> <div class='body'>$body</div>"; }  ?> 
    </div> 
</body>
</html>

write.php:

<?php
include('db.php');  
if($_SERVER["REQUEST_METHOD"] == "POST") {
    $title = $_POST['title'];
    $body = $_POST['body'];  
    $newurltitle = str_replace(" ","-",$title);
    $url = $newurltitle;  
    mysql_query("insert into blog(title,body,url) values('$title','$body','$url')");
    $blogurl= $url; 
} 
?>
<!DOCTYPE html>
<html> 
</head>  
    <body > 
    <div > 
    <h2><a href="<?php echo 'http://localhost/seo/article.php?url='.$title; ?>"><?php echo "http://localhost/seo/article/".$blogurl; ?></a></h2>  
    <form method="post" action="">
        <input type="text" name="title"/> 
        <textarea name="body" ></textarea> 
        <input type="submit"  value=" Publish "/> 
    </form>
    </div> 
</body>
</html>

的.htaccess

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-/]+)/$ article.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ article.php?url=$1

0 个答案:

没有答案