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.
在主.htaccess文件中。当有人试图热链接图像时,他会得到403响应。但是,他得到了404回应。如果我评论上面的行,我没有错误。
Seems to be due to Twig exception templates.
似乎是由于Twig异常模板。
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
.
我正在覆盖Twig异常模板中的一些错误模板。我通过添加文件成功覆盖了404错误模板:/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.
并尝试覆盖403错误模板。尝试添加:/app/Resources/TwigBundle/views/Exception/error403.html.twig但未显示。
There are not ErrorDocument
in Apache configuration, neither .htaccess
files.
Apache配置中没有ErrorDocument,也没有.htaccess文件。
Why is it throwing a 404 response, when it should throw a 403?
为什么它会抛出404响应,什么时候应该抛出403?
2 个解决方案
#1
0
Can you try this rule:
你能试试这条规则吗:
RewriteCond %{HTTP_REFERER} !^https?://mysite\.com [NC]
RewriteRule \.(gif|jpe?g|png|wbmp)$ - [NC,F]
#2
0
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:
而/ app / Resources / TwigBundle / views / Exception /是自定义异常页面的框架路径,当异常来自.htaccess文件或Apache配置时,您必须将路径指定为.htaccess文件或Apache配置,如下所示:
ErrorDocument 403 /errorTemplatesPath/error403.html.twig
ErrorDocument 404 /errorTemplatesPath/error404.html.twig
#1
0
Can you try this rule:
你能试试这条规则吗:
RewriteCond %{HTTP_REFERER} !^https?://mysite\.com [NC]
RewriteRule \.(gif|jpe?g|png|wbmp)$ - [NC,F]
#2
0
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:
而/ app / Resources / TwigBundle / views / Exception /是自定义异常页面的框架路径,当异常来自.htaccess文件或Apache配置时,您必须将路径指定为.htaccess文件或Apache配置,如下所示:
ErrorDocument 403 /errorTemplatesPath/error403.html.twig
ErrorDocument 404 /errorTemplatesPath/error404.html.twig