URLが次のように見えるかどうかを確認する一連のコマンドがあります
http://localhost/questions/32/new-question-from-peter
最後の部分が欠落している場合は、これにリダイレクトします。最後にフラグメントを許可します。
ただし、可能性を追加したいと思います
http://localhost/questions/32/new-question-from-peter?page= <int>
これが私のコードです
if($question){
$url = $_SERVER['REQUEST_URI'];
$dashed = $question->dashed_title;
$pattern = '/^\/questions\/[0-9]+\/'.$dashed.'(\/#[0-9]+)?$/i';
if (!preg_match($pattern, $url)){
// redirect_301 is a function that I wrote
redirect_301('http://'.$_SERVER['HTTP_HOST'].'/questions/'.$question->id.'/'.$dashed);
}
}
現時点では問題なく動作し、常に正しいパスにリダイレクトされます。しかし、それは私が追加することはできません
?page=<int>.
だから私はパターンが
$pattern = '/^\/questions\/[0-9]+\/'.$dashed.'((\/#[0-9]+)|(?[\w\d&=]+))?$/i';
しかし、これによりリダイレクトループが発生し、その理由がわかりません。手伝ってくれますか?