2

I get a internal server error after adding redirects to .htaccess - I've added 600 of them.

I check /var/logs/error.log

[Wed May 12 16:26:02.600394 2021] [core:alert] [pid 8071] [client 127.127.127.127:60816] /var/www/html/volumes/vol1/mysite/deployment_environments/master/code/.htaccess: Redirect takes one, two or three arguments, an optional status, then document to be redirected and destination URL, referer: my-dummy-example.com/

(IP addresses and site names changed to dummy values for privacy reasons)

But it doesn't tell me which line number this error is.

Obviously it has found an error on a line, so should be able to tell me. I have 600 redirects. It would be helpful if it could tell me the line number that the error is on.

I have looked through them and can't see any issue. This did work previously so I can't see what the problem is now. I've accounted for redirects with spaces by using the escape back slash and this had worked in previous testing.

I've already researched this but haven't yet found an answer:

therobyouknow
  • 471
  • 4
  • 8
  • 18

1 Answers1

1

Unfortunately, as far as I can tell, there is no way to get the "line number" on which the syntax error occurs to be reported in the Apache error log.

Ordinarily, you can increase the verbosity of logged messages by increasing the LogLevel in the server config. However, even increasing it to LogLevel trace8 (the "max") does not provide any more information with regards to "syntax" errors - which are reported as a core:alert, not by the actual module.

I've accounted for redirects with spaces by using the escape back slash and this had worked in previous testing.

This may actually be the problem... you can't backslash-escape spaces in the mod_alias Redirect (and RedirectMatch) directive(s) and attempting to do so could well result in the error you are seeing. (Maybe in your "previous testing" you were using a mod_rewrite RewriteRule directive?) For example, the following will result in the aforementioned error:

# ERROR: "Redirect takes one, two or three arguments, an optional status, then doc..."
Redirect 302 /foo\ bar /baz

If the URL argument contains spaces then surround the whole argument in double quotes instead:

# OK
Redirect 302 "/foo bar" /baz

This works with most modules/directives and is often preferable to backslash-escapes since it is usually more readable.

Aside: If, for instance, you were to combine this with what looks like a backslash-escape, ie. "/foo\ bar", then it will match a literal backslash (followed by a space)! (However, in order to actually match a literal backslash - that is encoded as part of the HTTP request - AllowEncodedSlashes On needs to be set in the server config, otherwise Apache will generate a 404.)

Another common cause of such errors are the use of line-end comments (which are not supported by Apache). For example:

# ERROR: "Redirect takes one, two or three arguments, an optional status, then doc..."
Redirect 302 /foo /bar  # Comment
MrWhite
  • 11,643
  • 4
  • 25
  • 40
  • 1
    +1 @ upvote and thank you for your time - I will read through your answer in detail. – therobyouknow May 13 '21 at 11:50
  • My following comment not directed you at all whatsoever(I'm very grateful!), but aimed rather at Apache software devs: "Unfortunately, as far as I can tell, there is no way to get the "line number" of the error reported in the Apache error log." - that is f\*cking ridiculous. Why can't it know?! If it knows there's an error then it can know which line that error is on. It's not a computationally impossible thing. The interpreter or whatever has been fed the directive, doesn't like it, so can jolly well report back what f\*cking line it didn't like. It aint rocket science, apache devs. – therobyouknow May 13 '21 at 11:51
  • Thanks again, as said above comment not directed at you Mr White at all whatsoever. I will endeavour to read your answer carefully. – therobyouknow May 13 '21 at 11:54