我遇到需要创建多个重定向的情况。
我想将/ blog重定向到/ food,这可以通过
轻松完成<html>
<head>
<meta charset="UTF-8">
<title>to-do-list</title>
<!-importanto css->
<link href="bootstrap.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<?php
error_reporting(E_ALL & ~E_NOTICE);
?>
<!--formulario com ação post-->
<form action="" method="post">
<h1> To Do List </h1>
<table class="table">
<tr>
<?php
unset ($_POST['nome']);
?>
<td><input type="text" name="nome" placeholder="nome" ></input></td>
<td><button>enviar</button></td>
</tr>
<?php
//definindo a variavel que vai capturar o input do usuário->
$name=($_POST['nome']);
//definindo a query que será passada ao mySQL
$query = "insert into itens (item) values ('{$name}')";
//definindo qual banco de dados deve ser acessado
$conexao = mysqli_connect('localhost', 'root', '', 'to-do-list');
//verifica se existe algo no $_POST, se tiver, mostra na tela e envia ao servidor.
if (isset($_POST['nome'])) {
mysqli_query($conexao, $query);
}
else {
}
//busca as tarefas listadas no banco e transforma em um array
function listaTarefas($conexao) {
$tarefas = array();
$resultado = mysqli_query($conexao, "select * from
itens");
//loop para colocar as tarefas antigas dentro do array $tarefas
while($item = mysqli_fetch_assoc($resultado)) {
array_push($tarefas, $item);
}
return $tarefas;
}
//para cada item do array tarefas, imprime o valor da coluna "item" na tabela
$tarefas = listaTarefas($conexao);
foreach($tarefas as $item) :
?>
<tr>
<td><?= $item['item'] ?></td>
<td>
</tr>
<?php
endforeach
?>
</table>
</form>
</body>
但是我还需要将/ blog / example重定向到/ another-example。但是因为我创建了以前的重定向,所以最终会发生这种情况:
Redirect 301 /blog /food
变为
/blog/example
而不是
/food/example
因为在考虑其他事情之前,它正在改变/博客/食物。
有任何帮助吗?谢谢!
答案 0 :(得分:2)
Redirect指令匹配uri的其余部分并将其附加到目标。要重定向特定的uri,您需要使用RedirectMatch。
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand"></li>
<li>
<a href="main.html"><i class="material-icons">home</i></a>
</li>
<li>
<a href="#overall" data-toggle="collapse" aria expanded="false">Overall </a>
<ul id="overall" class="nav-second collapse">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
</ul>
</li>
<li>
<a href="#dashboard" data-toggle="collapse" aria expanded="false">Dashboard </a>
<ul id="dashboard" class="nav-second collapse">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
</ul>
</li>
<li>
<a href="#service" data-toggle="collapse" aria expanded="false">Service </a>
<ul id="service" class="nav-second collapse">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
</ul>
</li>
<li>
</ul>
在测试之前清除浏览缓存。