繁体   English   中英

网站未正确重定向

[英]Site doesn't redirect properly

我正在创建一个strawpoll网站(有点像strawpoll.me,但你可以设置投票到期,它使用cookies),可以在http://www.makepoll.co.uk找到。

问题是,当你去它时,我们会被带到http://www.makepoll.co.uk/1 ,它应该带你到http://www.makepoll.co.uk/home

我的htaccess文件看起来像这样:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-z]+)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^([a-z]+)/([A-Z0-9]+)/?$ index.php?p=$1&s=$2 [L,QSA]
</IfModule>

我的index.php页面如下所示:

<?php require("backend/index.php");
if(empty($page)==TRUE)
{
    header("Location: home");
    die();
}
?><!DOCTYPE html>
<html>
<head>
<?php if(empty($part)==FALSE)
{
    echo "<link rel=\"stylesheet\" href=\"../frontend/jquery-ui.css\">\n";
    echo "<link rel=\"stylesheet\" href=\"../frontend/styles.css\">\n";
    echo "<script src=\"../frontend/jquery.js\"></script>\n";
    echo "<script src=\"../frontend/jquery-ui.js\"></script>\n";
}
else
{
    echo "<link rel=\"stylesheet\" href=\"frontend/jquery-ui.css\">\n";
    echo "<link rel=\"stylesheet\" href=\"frontend/styles.css\">\n";
    echo "<script src=\"frontend/jquery.js\"></script>\n";
    echo "<script src=\"frontend/jquery-ui.js\"></script>\n";
}
?>
<script>
$(function() {
    $( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<?php if(empty($part)==FALSE)
{
    echo "<a href=\"#content\" tabindex=\"", $tab++, "\"><img src=\"../frontend/content.png\" alt=\"Skip to Content\"></a>\n";
}
else
{        
    echo "<a href=\"#content\" tabindex=\"", $tab++, "\"><img src=\"frontend/content.png\" alt=\"Skip to Content\"></a>\n";
}
?>
<div id="pollbox">
<?php if(in_array("{$page}.php", $content)==TRUE)
{
    include("{$basedir}/content/{$page}.php");
}
else
{
    echo "<p>Page not found, I'm sorry</p>";
    http_response_code(404);
}
?>
</div>
<footer>
<ul>
<li><a href="../home/1" tabindex="<?php echo $tab++; ?>">Create New Poll</a></li>
<li><a href="../terms/1" tabindex="<?php echo $tab++; ?>">Terms of Service</a></li>
<li><a href="../terms/2" tabindex="<?php echo $tab++; ?>">Privacy Policy</a></li>
<li>Contact Us</li>
</ul>
</footer>
</body>
</html>

后端/ index.php页面如下所示:

<?php /* This file will contain the backend functions and set things up, such as the MySQL connection, and set the variables the site is going to use. This file line will connect to the SQL database. If there is a connection error, the script will be killed, and since there is no point continuing, a message will be displayed */
ob_start();

session_start();
$connection = new mysqli("localhost", "root", "", "example");
if($connection->connect_error)
{
    die("Sorry... I was unable to connect");
}
$basedir             = dirname(__FILE__);                         // This variable will hold the path to the current folder
$page                = strtolower($_GET["p"]);                    // This variable will hold the current page name
$part                 = $_GET["s"];                             // This variable will keep track of which part of the script the user is on
$tab                 = 1;                                                     // This variable will hold the tabindex
$content            = scandir("{$basedir}\content");        // This will scan the content folder and return an array 
unset($content[0], $content[1]);                                // This will unset the 0th and 1st element of the array 
include("{$basedir}/functions.php");                        // This will include the backend functions script
?>

你们能给我一些指示吗? 就我而言,它应该重定向到/ home

将此重写规则添加到列表中

RewriteRule ^([az]+)/home$ index.php?p=$1 [L,QSA]

希望这可以帮助

我猜你可以使用绝对路径来解决这个问题。 像这样:

标题('location: http//www.makepoll.co.uk/home/ ');

我不明白为什么你的网址上附加了1。

此外,您需要重构代码并重新考虑您的架构,但这是另一个问题)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM