我一直在编写一个php脚本,花了我几天的时间(我是个菜鸟)
这是我的密码:
<?php
require ('connect.php');
$requete = mysql_query('SELECT * FROM videos WHERE id="'.$_GET['id'].'"') or die(mysql_error());
if(mysql_num_rows($requete)=='0'){
}else{
while($resultats = mysql_fetch_array($requete)){
?> <!-- some html content --> <?php
}
}
mysql_close();
?>
</body>
</html>此脚本根据ID从我的数据库中检索内容。
http: //localhost/mysite/video/atest.php?id=1
我想知道我需要使用哪种url重写来检索一些关键字。我想要这样的网址:
http: //localhost/mysite/视频/1-第一视频-标题
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css|png|jpe?g|gif|js|mp3|3gp|ico)$
RewriteRule atest/([a-zA-Z0-9\-]+)-([0-9]+) atest.php?id=$1&url=$2[L,QSA]出什么事了?
我也想使用它,但是屏幕上没有显示任何内容(找不到这个页面)。
if($resultats["url"]!=$_GET["url"]) {
header ("location:/mysite/video/".$resultats["url"]."-".$resultats["id"]);
}它在我的表中搜索URL关键字。
谢谢!
发布于 2012-08-06 03:22:07
我认为这里的问题可能非常简单: RewriteRule捕获变量的方式错误,RewriteRule atest/([a-zA-Z0-9\-]+)-([0-9]+) atest.php?id=$1&url=$2[L,QSA]将匹配“atest/样例-42”,并将其映射到"atest.php?id=example&url=42“-- $1表示第一组括号,$2映射到第二个括号。试试print_r()或var_export() of $_GET
顺便说一句,在某些边缘情况下,这个正则表达式可能会出错,因为它并没有断言ID必须出现在末尾--所以“atest/范本-2-word- 42”最终可能会将ID选择为2,而不是42。添加一个"$“应该可以修复这个问题:RewriteRule atest/([a-zA-Z0-9\-]+)-([0-9]+)$ atest.php?id=$1&url=$2 [L,QSA]
如果重写规则根本不起作用(您的问题不清楚结果是什么),那么在Apache的.htaccess处理中可能会有一些微妙之处。
https://stackoverflow.com/questions/11570720
复制相似问题