I am trying to move rewrites from .htaccess files to
/etc/apache2/conf.d/includes/pre_main_global.conf
For testing purposes, the complete content of pre_main_global.conf is:
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https://domain.com" [R=301,L]
This rewrite works fine in an .htaccess file but does not work at all in pre_main_global.conf
The file permission for pre_main_global.conf is 644
The online tester at htaccess tester
madewithlove does not show any syntax errors.
My main apache configuration file is /etc/apache2/conf/httpd.conf
That file says:
# Administrator locations for safely altering httpd.conf
Include "/etc/apache2/conf.d/includes/pre_main_global.conf"
I have root access. Using a terminal program I did:
apachectl -D DUMP_INCLUDES
One of the configuration files listed is:
/etc/apache2/conf.d/includes/pre_main_global.conf
This appears to indicate that the file pre_main_global.conf is not simply being ignored.
Any idea why my rewrite in pre_main_global.conf is not working?
I started a different thread asking how to get rewrite error messages in apache 2.4 but so far there is no answer in that thread.
/etc/apache2/conf.d/includes/pre_main_global.conf
For testing purposes, the complete content of pre_main_global.conf is:
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https://domain.com" [R=301,L]
This rewrite works fine in an .htaccess file but does not work at all in pre_main_global.conf
The file permission for pre_main_global.conf is 644
The online tester at htaccess tester

My main apache configuration file is /etc/apache2/conf/httpd.conf
That file says:
# Administrator locations for safely altering httpd.conf
Include "/etc/apache2/conf.d/includes/pre_main_global.conf"
I have root access. Using a terminal program I did:
apachectl -D DUMP_INCLUDES
One of the configuration files listed is:
/etc/apache2/conf.d/includes/pre_main_global.conf
This appears to indicate that the file pre_main_global.conf is not simply being ignored.
Any idea why my rewrite in pre_main_global.conf is not working?
I started a different thread asking how to get rewrite error messages in apache 2.4 but so far there is no answer in that thread.
Last edited by a moderator: