build_apache_conf groups all rewritecond and rewriterules together

compuminus

Registered
Apr 9, 2008
4
0
51
I have a sequence of rewrite rules in my httpd.conf as follows:

RewriteCond Condition#1
RewriteRule Rule#1
RewriteCond Condition#2
RewriteRule Rule#2

However, whenever cpanel rebuilds the httpd.conf file, it groups all of the rewritecond and rewrite rules together, effectively breaking their functionality:

RewriteCond Condition#1
RewriteCond Condition#2
RewriteRule Rule#1
RewriteRule Rule#2

Unless I'm overlooking something, this appears to be a MAJOR BUG. In my case, it's so bad that the rewrite rules create an infinite redirect and make the domain inaccessible until I correct the rewrite ordering.

Please clarify if I am doing something wrong. For now I just avoid having cpanel rebuild the apache conf file, and just use the distiller followed by an httpd restart, but sometimes having cpanel rebuild the conf file is unavoidable, so I always have to keep a httpd.conf backup.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
38
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
You would not add anything to httpd.conf directly. These should be done as includes instead.

If you need them for the main configuration, then you can use /usr/local/apache/conf/includes area or WHM > Apache Configuration > Include Editor area.

If these are for some select virtual host entries, then instead put them into /usr/local/apache/conf/userdata at the applicable location. Here's a discussion on using includes for the Virtual Host sections:

Changes Contained within a VirtualHost Directive
 

compuminus

Registered
Apr 9, 2008
4
0
51
So I would place all prior custom <Directory "PATH">xxxx</Directory> directives inside the pre_virtualhost_global.conf file? For some reason any changes in this file aren't getting incorporated into httpd.conf when running the two in sequence:

/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
 
Last edited:

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
38
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
Where in Apache do you normally put these includes? Do you really put them at the end of the Virtual Host section after all Virtual Host entries or do you normally put them before the Virtual Host entries? If you normally put them before those entries, you would want to use pre_main_global.conf and then rebuild Apache and restart Apache.

Of note, you will *not* see the entries go into httpd.conf itself. The files are included, which means Apache reads any includes into the file. If you see post_virtualhost_global.conf as an include in httpd.conf file, then it is including the entries into the file and reading those entries.