【问题标题】:HTACCESS resulting in error 404HTACCESS 导致错误 404
【发布时间】:2016-12-17 21:30:25
【问题描述】:

我在子目录中有以下 htaccess 代码

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([0-9]+).html$ order-details.php?id=$1 [NC,L]

它工作正常。问题是该目录中的每个其他页面都会给出错误 404。

链接 example.com/sub/sub/123456.html 工作正常。此外,example.com/sub/sub/ 工作正常,因为我在子目录中有一个索引文件。但是,example.com/sub/sub/anotherpage.html 给出错误 404。删除 htaccess 解决了一个问题并带来了另一个问题。

example.com/sub/sub/

【问题讨论】:

  • 所以基本上您希望123456.html 转到order-details.php 页面,但anotherpage.html 只显示该目录中存在的真实 anotherpage.html 页面?
  • 是的,这正是我想要的

标签: apache .htaccess mod-rewrite


【解决方案1】:

你可以添加

RewriteCond %{REQUEST_FILENAME} !-f

到您的代码以确保忽略文件夹中存在的文件。

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+).html$ order-details.php?id=$1 [NC,L]

【讨论】:

  • 好吧,这很有趣,它适用于除一个之外的所有其他文件:-o
  • 您确定文件名正确吗?这段代码应该可以工作。
  • 是的。文件名是正确的。如果我删除 htaccess 代码,链接就可以正常工作。
  • .htaccess 文件在sub/sub/ 文件夹中?你那里还有其他配置吗?你用的是哪个版本的apache?
  • 我刚刚在我的服务器中检查了这个,它工作得很好。
【解决方案2】:

您试图访问带有字母数字名称的页面。 但是,在您的 htaccess 中,它仅适用于数字。

RewriteRule ^([0-9]+).html$ order-details.php?id=$1 [NC,L] 由于[0-9],只能访问数字名称

如果你想重定向alpha数字,你必须使用另一个掩码。也许[0-9A-Za-z]?

【讨论】:

  • 我重命名的页面是数字。如上所述,123456.html 转到 order-details.php 页面,但 anotherpage.html 仅显示该目录中存在的 real anotherpage.html 页面
【解决方案3】:

现在工作。看来我也必须删除 sub/sub/ 中 htaccess 中的 .php 扩展名。

【讨论】:

    猜你喜欢
    • 2015-05-24
    • 2021-10-04
    • 1970-01-01
    • 2019-12-10
    • 2022-12-10
    • 1970-01-01
    • 2010-12-17
    • 2021-04-19
    • 2015-02-16
    相关资源
    最近更新 更多