![](/img/trans.png)
[英]Getting 403 Forbidden error message when trying to access a cusotm route
[英]Irrational Forbidden 403 Error Message
我有一个博客,上面有一个add-post.php
页面,其中包含一个带有操作的简单表格:
<form id="form" action="add-post-php.php" method="POST" enctype="multipart/form-data">
然后,我将文件add-post-php.php
与add-form.php
放在同一文件夹中。 因此,我在表单中输入博客的详细信息,然后按提交并获得:
禁止的
您无权访问此服务器上的/add-post-php.php。
此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。
我已经在本地主机上对其进行了测试,并且可以正常工作,该文件的权限设置为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¤tpage=$2 [NC,L,QSA]
RewriteRule ^posts/([\w-]+)/?$ posts.php?category=$1 [NC,L,QSA]
RewriteRule ^posts/([\w-]+)/([0-9]+)/?$ posts.php?category=$1¤tpage=$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错误日志,然后看到以下消息:
[2015年10月22日星期四13:04:14.575567] [:错误] [pid 1041578] [客户端74.125.76.51:56087]文件不存在:/ home / fulldist / public_html / ***。com / feed.php,
[2015年10月22日星期四09:53:14.646744] [:错误] [pid 944286] [客户端31.13.113.90:59997]文件不存在:/ home / fulldist / public_html / ***。com / blog.php。
的确feed.php和blog.php不存在,但是为什么要尝试查找它们呢?
这没错吗
header("Location: post.php?id=$id");
您是否不需要此标题
header("Location: posts/$id");
根据这个规则
RewriteRule ^posts/([0-9]+)/?$ posts.php?currentpage=$1 [NC,L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.