当投掷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?

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

Can you try this rule:

RewriteCond %{HTTP_REFERER} !^https?://mysite\.com [NC]
RewriteRule \.(gif|jpe?g|png|wbmp)$ - [NC,F]