【问题标题】:Irrational Forbidden 403 Error Message不合理的禁止 403 错误消息
【发布时间】:2015-10-22 11:24:59
【问题描述】:

我有一个带有 add-post.php 页面的博客,其中包含一个带有操作的简单表单:

<form id="form" action="add-post-php.php" method="POST" enctype="multipart/form-data">

然后,我将文件 add-post-php.phpadd-form.php 放在同一文件夹中。所以我在表单中输入了我博客的详细信息,然后按提交并获取:

禁止

您无权访问此服务器上的 /add-post-php.php。

此外,在尝试访问时遇到 404 Not Found 错误 使用 ErrorDocument 来处理请求。

我已经在我的本地主机上测试过,它工作正常,文件的权限设置为0644,但我也在0755尝试过,没有任何改进。我的 .htaccess 文件没有问题,目录中也没有其他 .htaccess 文件。

我的add-post-php.php 完整脚本是:

<?php
include("php/settings.php"); // Contains DB Connections
?>
<?php
$id= time();
$month = date("m");
$year = date("Y");
$path = "images/posts/$year/$month/";

$section = $_POST["section"];
$category = $_POST["category"];
$credit = $_POST["credit"];
$title = ucwords($_POST["title"]);
$text = $_POST["text"];
$exclusive = $_POST["exclusive"];

$added = date("Y-m-d H:i:s");

$photo = $_FILES["photo"]["name"];
$ext = substr(strrchr($photo, '.'), 1);
?>
<?php
$insert_sql = "INSERT INTO posts (id, section, category, credit, title, article, exclusive, added) VALUES('$id', '$section', '$category', '$credit', '$title', '$text', '$exclusive', '$added')";
$insert_res = mysqli_query($con, $insert_sql);
if(mysqli_affected_rows($con)>0){
move_uploaded_file($_FILES["photo"]["tmp_name"],"$path" . $id . "." . $ext);
}
else{
echo "0";
exit();
};
?>
<?php
header("Location: post.php?id=$id");
exit();
?>

有没有人知道为什么当文件明确存在并且权限正确时我会收到禁止错误?

这是我的 .htaccess:

Options -MultiViews

DirectoryIndex posts.php

RewriteEngine On

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

RewriteRule ^posts/([0-9]+)/?$              posts.php?currentpage=$1 [NC,L,QSA]

RewriteRule ^section/([\w-]+)/?$            section.php?section=$1 [NC,L,QSA]
RewriteRule ^section/([\w-]+)/([0-9]+)/?$   section.php?section=$1&currentpage=$2 [NC,L,QSA]

RewriteRule ^posts/([\w-]+)/?$              posts.php?category=$1 [NC,L,QSA]
RewriteRule ^posts/([\w-]+)/([0-9]+)/?$     posts.php?category=$1&currentpage=$2 [NC,L,QSA]

RewriteRule ^post/([0-9]+)/([\w-]+)/?$      post.php?id=$1&title=$2 [NC,L,QSA]

RewriteRule ^sites/([0-9]+)/?$              sites.php?currentpage=$1 [NC,L,QSA]

RewriteRule ^posts posts.php
RewriteRule ^section section.php
RewriteRule ^sites sites.php

RewriteRule ^about about.php
RewriteRule ^advertise advertise.php
RewriteRule ^subscribe subscribe.php

文件夹结构:

我刚刚再次检查了 php 错误日志,我看到了这些消息:

[Thu Oct 22 13:04:14.575567 2015] [:error] [pid 1041578] [client 74.125.76.51:56087] 文件不存在:/home/fulldist/public_html/***.com/feed。 php,

[Thu Oct 22 09:53:14.646744 2015] [:error] [pid 944286] [client 31.13.113.90:59997] 文件不存在:/home/fulldist/public_html/***.com/blog。 php。

feed.php 和 blog.php 确实不存在,但它为什么要查找它们呢?

【问题讨论】:

  • 尝试将完整路径放入action属性中。
  • 谢谢@Daan,但我昨天已经试过了,遇到了完全相同的问题
  • 你能展示你的目录结构吗?
  • 你有一个.htaccess 文件可能会做一些奇怪的事情
  • @RiggsFolly,我看不到,我已经在上面添加了我的 htaccess 代码

标签: php apache .htaccess


【解决方案1】:

这不是错

header("Location: post.php?id=$id");

你不需要这个作为标题

header("Location: posts/$id");

基于此规则

RewriteRule ^posts/([0-9]+)/?$              posts.php?currentpage=$1 [NC,L,QSA]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 2017-02-27
    • 1970-01-01
    • 2021-03-21
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多