【问题标题】:htaccess URL not found未找到 htaccess URL
【发布时间】:2018-09-04 15:33:16
【问题描述】:

我有一个 .htaccess 文件和代码:

#command_players
RewriteRule ^command_players/([0-9]+)?$ command_players.php?id=$1 [NC,L]

当用户输入正确时,我的登录页面应该重定向到 command_players.php 页面:

if (password_verify($_POST['pass'], $results['pass'])) {
    $_SESSION['command']= 'ok';
    $_SESSION['id'] = $results['id'];
    redirect("command_players/$results[id]/");
}

但我收到如下错误:

在此服务器上找不到请求的 URL /site/command_players/18/,

/site/command_players.php 工作时。

我不擅长htaccess,我做错了什么?

【问题讨论】:

  • 您的 RewriteRule 既不包含 site/ 前缀也不包含您在请求 URL …players/18/ 中的 / 后缀
  • 试试这个:RewriteRule ^command_players/([0-9]+)?$ /site/command_players.php?id=$1 [NC,L]
  • 在这些情况下,拥有一个与文件夹名称“相同”(减去后缀)的脚本文件通常会导致麻烦;尝试禁用 MultiViews。

标签: php .htaccess friendly-url


【解决方案1】:

您需要在 htaccess 文件的正则表达式中包含斜杠 (/),如下所示。

? 表示“前一个零或一个”,因此/? 表示“没有斜线或一个”,这与您描述的模式相对应。

#command_players
RewriteRule ^command_players/([0-9]+)/?$ command_players.php?id=$1 [NC,L]

有用的资源

【讨论】:

  • 感谢您的建议。我使用:#command_players RewriteRule ^command_players/([0-9]+)/?$ command_players.php?id=$1 [NC,L] 只是复制您的建议,但不幸的是问题仍然存在。
【解决方案2】:

问题与文件夹有关,我在登录重定向中错过了“/”。现在可以了:

#command_players
RewriteRule ^command_players/([0-9]+)/?$ site/command_players.php?id=$1 [NC,L]



 if (password_verify($_POST['pass'], $results['pass'])) {
                                $_SESSION['command']= 'ok';
                                $_SESSION['id'] = $results['id'];
                                //redirect("command/list.php/$results[id]/");
                                redirect("/command_players/{$results['id']}/");
                            }

【讨论】:

    猜你喜欢
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    相关资源
    最近更新 更多