doukai1226 2013-11-05 11:06
浏览 40
已采纳

当投掷403时投掷404响应

I have the next rule:

RewriteCond %{HTTP_REFERER} ^$ [OR]
RewriteCond %{HTTP_REFERER} !^https?://itransformer.*$ [NC]
RewriteRule \.(gif|jpe?g|png|wbmp)$ - [R=403,L]

in the main .htaccess file. When anyone try to hotlink an image, he will get a 403 response. However, he's getting a 404 response. If I comment the lines above, I get no error.

Seems to be due to Twig exception templates.

I'm overriding some error templates from Twig exception templates. I've successfully overridden the 404 error template by adding the file: /app/Resources/TwigBundle/views/Exception/error404.html.twig.

And tried to override the 403 error template. Tried adding: /app/Resources/TwigBundle/views/Exception/error403.html.twig but is not shown.

There are not ErrorDocument in Apache configuration, neither .htaccess files.

Why is it throwing a 404 response, when it should throw a 403?

  • 写回答

2条回答 默认 最新

  • doo6568 2013-11-19 12:45
    关注

    I've found out the issue:

    While /app/Resources/TwigBundle/views/Exception/ is the framework path to customize exception pages, when the exception comes from an .htaccess file or Apache configuration, you must specify the path also into .htaccess file or Apache configuration, like this:

    ErrorDocument 403 /errorTemplatesPath/error403.html.twig
    ErrorDocument 404 /errorTemplatesPath/error404.html.twig
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址