【问题标题】:.htaccess 403 Forbidden.htaccess 403 禁止访问
【发布时间】:2016-12-16 11:53:51
【问题描述】:

这是我的 HTML 文件:

<html lang="en">
<body>
<h1>This is the HTML file.</h1>
</body>
</html>

PHP 文件:

<?php
echo "<h1>This is the PHP file.</h1>";
?>

.htaccess 文件:

RewriteEngine On
RewriteRule ^/?test.html$ test.php [L]

当我加载 test.html 时出现错误:

禁止

您无权访问此服务器上的 /modul-1-froland/rewrite_test/test.html。

而不是加载我的 test.php 文件。知道我该如何解决吗?在 MAMP 中工作 (http://localhost/modul-1-froland/rewrite_test/test.html)

【问题讨论】:

  • 我想知道你想要做什么以及你想要做什么。 htaccess?
  • 这只是一个简单的例子,我想了解 .htaccess 文件是如何工作的。以这个简单的例子开头

标签: php html apache .htaccess


【解决方案1】:

您的规则规定您的 URL 必须以 test.html 开头,并在开头加上可选的 /,但是您访问的 /modul-1-froland/rewrite_test/test.html 不以 test.html 开头

改成

RewriteEngine On
RewriteRule test.html$ test.php [L]

匹配所有以test.html结尾的网址

【讨论】:

  • 您的.htaccess 在您的服务器根目录中吗?还启用了 mod_rewrite 吗?您的站点配置是否允许覆盖?还要检查 htaccess.mwl.be 以对 .htaccess 规则进行快速测试。
  • .htaccess 文件在我的文件夹中(test.php 和 test.html 在哪里)。在站点中进行了测试,似乎可以正常工作,但在我的本地主机中却没有。也许 mod_rewrite 已禁用
猜你喜欢
  • 1970-01-01
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-04
  • 1970-01-01
  • 2020-07-20
  • 2011-12-27
相关资源
最近更新 更多