7

How do you troubleshoot Apache redirects in production? I know there's a logging feature somewhere that lets you log all the redirects that happen...

Andrew B
  • 32,588
  • 12
  • 93
  • 131
deadprogrammer
  • 1,691
  • 7
  • 24
  • 25

3 Answers3

7

To log what's going on in the mod_rewrite module you need to set RewriteLog and RewriteLogLevel:

RewriteLog         /path/to/mod_rewrite.log
RewriteLogLevel    2

in your Apache config (you can't set them in your .htaccess).

Note that logging has changed in Apache 2.4.

Cristian Ciupitu
  • 6,396
  • 2
  • 42
  • 56
Nathan
  • 1,187
  • 6
  • 9
2

To get additional debugging information for debugging Apache issues (such as redirects), you can add RewriteLog and RewriteLogLevel to the configuration. The specifics of the configurations are different between Apache 2.2 and 2.4, so please check the version of Apache you are running.

Please check the logs, as they may tell you the specific details of what is causing the redirect. In general, Apache redirects can be troubleshot by adding the following to the Apache 2.4 configuration:

LogLevel alert rewrite:trace6

reference: http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging

I see that you have replaced the specifics of the Apache configuration for security. This is good, but I can't check the SSL for the domain due to this. There could also be an issue with Server Name Indication (SNI) which the browser is using for that domain name which does not match the Apache configuration.

It may be possible that DirectAdmin has added a configuration in addition to another configuration. Please check that you do not have multiple sections with the same IP address and port.

You may also want to confirm the domain matches the website's configuration. Depending on what CMS you are running (Magento, WordPress, Joomla!, etc.), it could be redirecting back to the original domain which Apache redirected from.

  • Hello and welcome to ServerFault. Don't you think your answer could be trimmed down a bit? – kubanczyk May 08 '18 at 15:20
  • I'm not sure what details I should leave out. If you tell me what to trim, I will be happy to erase the information from the response. – classmember Jun 19 '18 at 12:28
0

I generally create my own verbose CustomLog. In it, I include the HTTP Response header Location

I also include other things such as the response time and HTTP Request header X-Forwarded-For, amongst a select other few things.

Cameron Kerr
  • 4,069
  • 19
  • 25