.htaccess在xampp上不起作用(Windows 7)

时间:2014-06-29 01:16:00

标签: php .htaccess xampp

我现在正在设置我的.htaccess文件以使用友好网址(手动)。但是,当我转到网址时,服务器会显示错误404

RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  

Rewriterule ^register$ register.php 

我确定已启用 mod_rewrite ,因为我在使用phpinfo()时看到了它。

4 个答案:

答案 0 :(得分:11)

即使mod-rewrite已启用,默认情况下也不会为.htaccess个文件启用。

保持呼吸

  • 打开xampp控制面板
  • 停止Apache
  • 单击Apache行上的Config按钮,然后选择httpd.conf
  • 在该文件中,搜索xampp/htdocs">
  • 之类的内容
  • 稍微低一点,您可能会看到如下所示的行:# AllowOverride All。删除#,这是一条评论
  • 或者,搜索AllowOverride All,确保它位于右侧部分,然后移除评论#
  • 保存文件
  • 重新启动Apache,祈祷,交叉手指,屏住呼吸

答案 1 :(得分:0)

签入您标记的httpd.conf,查看此属性

AllowOverride All

AllowOverride授权使用htaccess文件。

答案 2 :(得分:0)

此列表可能很旧,但是仍然有用,因此为了使其更加安全,最好添加几行。

Deny from all
Allow from 127.0.0.1 ::1 localhost
Allow from .htaccess

此外,.htaccess文件会减慢服务器的速度,因此最好参考xampp文档以获取最佳实践。

希望有帮助。

答案 3 :(得分:0)

<?php
session_start();

$userKey = $_POST['userKeySubmitted'];
$keylist = file('priv/keys.txt');

$success = false;
foreach ($keylist as $key) {
    $user_details = explode('|', $user);
    if ($user_details[0] == $userKey) {
        $success = true;
        if ($success) {
            header('Location: user.php');
            $_SESSION['userKey'] = $userKey;
            break;
        } else {
            break;
        }
    }
}
?>

....

<form method="post" action="index.php">
    <input type="text" name="userKeySubmitted" class="form-control" placeholder="XXXX-XXXX-XXXX-XXXX">
    <br>
    <button type="submit" name="submit" class="btn btn-info btn-fill pull-right">Login</button>
    <div class="clearfix"></div>
</form>




In user.php:

<?php
session_start();
if (isset($_SESSION['userKey'])) {
    $key = $_SESSION['userKey'];
    echo "<h1>Welcome</h1>";
} else {
    header('Location: index.php');
    die();
}
?>

如果我们要删除index.php表单url,首先我们在项目的根目录上创建一个.htaccess文件,不带任何扩展名。并将此代码添加到此文件中,然后删除index.php Application / config / config.php