找不到htaccess网址

问题描述 投票:0回答:2

我有一个.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,我做错了什么?

php .htaccess friendly-url
2个回答
0
投票

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

?的意思是“零或之前的”,所以/?的意思是“没有斜线或一个”,这与你描述的模式相对应。

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

有用的资源


0
投票

问题是关于文件夹,我在登录重定向中错过了'/'。它现在有效:

#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']}/");
                            }
© www.soinside.com 2019 - 2024. All rights reserved.