I've upgraded my Apache 2.2 web server to 2.4 today and then some Wordpress installations started to get infinite loops from non-www to www and from www to non-www :(

Removing .htaccesss didn't helped.

How to solve this ? Example domain config:

SetEnvIf X-Forwarded-Proto https HTTPS=1

ServerAdmin webmaster@internet.az.pl

ServerName internet.az.pl

ServerAlias www.internet.az.pl

DocumentRoot "/home/admin2/komputery"

DirectoryIndex index.php index.html index.shtml index.htm index.pl index.py index.cgi index.rb default.htm Default.aspx Default.asp

ScriptAlias /cgi-bin/ "/home/admin2/internet.az.pl/cgi-bin/"

<IfModule mod_fastcgi.c>
        Alias /internet.az.pl.0fake "/home/admin2/komputery/internet.az.pl.0fake"
        #FastCGIExternalServer "/home/admin2/komputery/internet.az.pl.0fake" -host -idle-timeout 300 -pass-header Authorization
        FastCGIExternalServer "/home/admin2/komputery/internet.az.pl.0fake" -socket /opt/configs/php-fpm/sock/admin2.sock -idle-timeout 300 -pass-header Authorization
        AddType application/x-httpd-fastphp .php
        Action application/x-httpd-fastphp /internet.az.pl.0fake
        <Files "internet.az.pl.0fake">
                RewriteCond %{REQUEST_URI} !internet.az.pl.0fake

<Directory "/home/admin2/komputery/">
        AllowOverride All
        <IfVersion < 2.4>
                Order allow,deny
                Allow from all
        <IfVersion >= 2.4>
                Require all granted
        Options +ExecCGI
        <FilesMatch \.(cgi|pl)$>
                SetHandler cgi-script

<IfModule mod_php5.c>
        php_admin_value sendmail_path "/usr/sbin/sendmail -t -i"
        php_admin_value sendmail_from "internet.az.pl"
        Include /home/kloxo/client/admin2/prefork.inc

<Location "/">
        Allow from all
        Options -Indexes -FollowSymlinks +SymLinksIfOwnerMatch

        <IfModule mod_php5.c>
                php_admin_value open_basedir "/home/admin2:/tmp:/usr/share/pear:/var/lib/php/session/:/home/kloxo/httpd/script:/home/kloxo/httpd/disable/:/usr/bin"

CustomLog "/home/httpd/internet.az.pl/stats/internet.az.pl-custom_log" combined
ErrorLog "/home/httpd/internet.az.pl/stats/internet.az.pl-error_log"

and also httpd.conf:

   ServerTokens Prod

ServerRoot "/etc/httpd"

# MR -- must be disable here because can not overrite! -- importance for proxy-to-apache
# Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted

# Further relax access to the default document root:
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

<IfModule dir_module>
    DirectoryIndex index.html

<Files ".ht*">
    Require all denied

ErrorLog "logs/error_log"

LogLevel error

<IfModule log_config_module>
        ## MR -- change %h to %a to fix mod_remoteip issue
    LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%a %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

    CustomLog "logs/access_log" combined

<IfModule alias_module>
    # Alias /webpath /full/filesystem/path
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    #AddHandler cgi-script .cgi
    #AddHandler type-map var

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic

Alias /error/ "/home/kloxo/httpd/error/"

<IfModule mod_negotiation.c>
    <IfModule mod_include.c>
        <Directory "/home/kloxo/httpd/error/">
            AllowOverride None
            Options IncludesNoExec
            AddOutputFilter Includes html
            AddHandler type-map var
            <IfVersion < 2.4>
                Order allow,deny
                Allow from all
            <IfVersion >= 2.4>
                Require all granted
                LanguagePriority en es de fr
            ForceLanguagePriority Prefer Fallback

        #ErrorDocument 500 "The server made a boo boo."
        #ErrorDocument 404 /missing.html
        #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
        #ErrorDocument 402 http://www.example.com/subscription_info.html

        ErrorDocument 401 /error/401.html
        ErrorDocument 403 /error/403.html
        ErrorDocument 404 /error/404.html
        ErrorDocument 500 /error/500.html
        ErrorDocument 501 /error/501.html
        ErrorDocument 503 /error/503.html
        ErrorDocument 504 /error/504.html

EnableSendfile on

IncludeOptional conf.d/*.conf

First... stop using IfModule on bits that aren't optional. (not sure what is or is not required) They're only useful if you have a fall-back way of recovering if that module doesn't exist or isn't loaded. Otherwise, apache will start without error... despite the fact that 90% of your config won't actually be loaded.

A quick way to test and ultimately fix... is to remove all of the IfModule statements... and then restart apache. You'll almost certainly get errors. Read the error logs. Look at what errors you get... (i.e. can't load blah blah) and enable/install/rebuild the necessary modules that are required to make your site work.

  • It's a part of larger config for many options like mod_ruid2, mod_suphp etc. – Marek Zakrzewski Jul 1 '15 at 21:31
  • That's fine. That doesn't invalidate my answer. If it's not optional... you should error rather than permit apache to load. IfModule silences those errors... which is bad. – TheCompWiz Jul 1 '15 at 21:34
  • OK. Does it matter if I use nginx as reverse proxy before apache ? It was working well before upgrade to apache 2.4. – Marek Zakrzewski Jul 1 '15 at 21:35
  • It shouldn't make any difference. As long as your nginix server is behaving properly... it won't affect Apache. (and vise-versa) – TheCompWiz Jul 1 '15 at 21:36
  • I just found all my .htaccess redirections from www to non-www also does not work, but no redirect loop. – Marek Zakrzewski Jul 1 '15 at 21:37

The problem was in nginx - changing line:

proxy_set_header X-Host $var_domain;


proxy_set_header X-Host $host;

fixed the problem

  • Can you mark your answer as valid ? – Froggiz Dec 18 '15 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.