【问题标题】:need to use www.mydomain.com/filename/ instead of www.mydomain.com/file.php?id=1需要使用 www.mydomain.com/filename/ 而不是 www.mydomain.com/file.php?id=1
【发布时间】:2021-05-09 10:58:33
【问题描述】:

www.mydomain.com/filename/ 而不是www.mydomain.com/file.php?id=1

目前我正在开发一个自动索引站点脚本

从 index.php 我放了一个超链接到下载页面下载页面和我放的 file.php 页面

$id=$_REQUEST['id'];
$query = "update mydatabase SET views = views+1 where id ='".$id."'";
$update = mysqli_query($con,$query) or die(mysql_error());
$query = "SELECT * from mydatabase where id='".$id."'";
$result = mysqli_query($con,$query) or die(mysql_error());
$row = mysqli_fetch_assoc($result);


<?php echo $row['id'];?>
<?php echo $row['name'];?>
<?php echo $row['size'];?>

等等。

当我点击下载页面时,它会将我重定向到www.mydomain.com/file.php?id=1 页面并显示相关文件详细信息。

但我确实需要将上面的网址更改为www.mydomain.com/song/file-name

请问有人可以在这方面给我建议或帮助吗??

【问题讨论】:

  • 嗨,Ayesha,欢迎来到 stackoverflow。我认为您不能仅使用 htaccess 将/file.php?id=1 转为/song/filename/。您必须使用文件名本身作为查询字符串的参数,以便 htaccess 可以解决。一旦你使用文件名作为参数,你就可以用RewriteRule "^song/(.+)" "file.php?filename=$1" 解决你的重写问题(不过需要解决一些细微差别)。
  • 我已将我的代码更改为“song.php?title=$title”它也可以正常工作我现在可以从 .htaccess 更改网址吗??
  • 是的,规则然后变成RewriteRule "^song/(.+)" "song.php?title=$1" 但是,我的记忆有点模糊,有些事情需要考虑,例如实际的文件/文件夹。但先试一试。
  • 如何避免上述代码的sql注入请帮助我??

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


【解决方案1】:

也许你可以在你的下载页面上试试这个。

history.replaceState(null, null, '/song/file-name')

【讨论】:

  • 我在哪里可以放 tis 代码??下载页眉??
  • 以上是js代码,放在script标签中。
猜你喜欢
  • 2011-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-03
  • 2011-05-08
  • 2023-03-18
  • 1970-01-01
相关资源
最近更新 更多