Why is PHP mod_rewrite Not Working?
So URL rewriting is not being run when accessing the Apache web server. Even though mod_rewrite is enabled and loaded and the mod_rewrite rules in the .htaccess file all seem correct. It may be that the Apache default configuration needs changing. The Apache configuration is controlled by directives. The AllowOverride directive determines which directives in .htaccess files can be run. Prior to Apache 2.3.8 the default setting for this was All, allowing, by default, all directives in .htaccess files to be used. From Apache 2.3.8 the AllowOverride directive default was set to None. Effectively stopping .htaccess processing.
Set Apache AllowOverride Directive to FileInfo or All
To fix common mod_rewrite not working issues for PHP applications (e.g. WordPress) set the AllowOverride directive to FileInfo. Edit the Apache configuration file httpd.conf. Here is an example for a CentOS 7 server for the default public HTML directory (/var/www/html). Assuming the web server is accessed via Secure Shell (SSH) change to the /etc/httpd/conf directory:
# cd /etc/httpd/conf
Use vi to edit the Apache configuration file httpd.conf:
# vi httpd.conf
Use vi to Edit httpd.conf and Set AllowOverride to FileInfo
Move to the <Directory "/var/www/html"> section (in vi type command /<D then Enter and n three times, or page through the file to find it). The AllowOverride setting will be set to None. It can be changed to All but for mod_rewrite the setting FileInfo is sufficient. In vi enter insert mode with the Insert key and change the line AllowOverride None to AllowOverride FileInfo. Save the httpd.conf file, use the escape key and enter the write and quit vi command using :wq.
Restart Apache to Register the AllowOverride Change
Apache needs to read the new AllowOverride configuration. The server could be restarted or just restart Apache:
# apachectl restart
For further information on AllowOverride see the Apache Core Features documentation.
Author:Daniel S. Fowler Published: Updated: