【问题标题】:php htaccess redirect 404 error pagephp htaccess 重定向 404 错误页面
【发布时间】:2013-06-09 05:50:42
【问题描述】:

我正在构建一个 LAMP 应用程序 www.testing.com,并且我有一个图片网址 www.testing.com/image/folderA/a.jpg

我想在 .htacess 中有一个重写规则,这样如果用户导航到 /image/foldera 中不存在的图像,他将被重定向到另一个 URL 为 www.testing.com/image/folderB/b.jpg 的图像。

这是我的代码。

RewriteRule ^image/folderA/(.*\.(jpg|gif|png))$ http://%{SERVER_NAME}/image/folderB/b.jpg [R=404,L]

但是,这不起作用,因为应该返回图像的 www.testing.com/image/folderA/a.jpg 会给出 404。知道为什么吗?

【问题讨论】:

    标签: php .htaccess mamp lamp


    【解决方案1】:

    使用 R 标志时,您需要牢记以下几点:

    However, if a status code is outside the redirect range (300-399) then the substitution string is dropped entirely, and rewriting is stopped as if the L were used.

    http://httpd.apache.org/docs/trunk/rewrite/flags.html#flag_r

    这意味着您的重写规则正在删除替换字符串并将所有对指定文件的请求重定向到内置的 404 页面。

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      • 2016-01-06
      • 2011-12-05
      • 1970-01-01
      • 2023-03-27
      • 2018-10-14
      相关资源
      最近更新 更多