As of CentOS version 7, the
mod_rewrite Apache module is enabled by default. We will verify this is the case with the httpd command and -M flag, which prints a list of all loaded modules:
- httpd -M
Output
. . .
remoteip_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
slotmem_plain_module (shared)
. . .
If the
rewrite_module does not appear in the output, enable it by editing the 00-base.conf file with the vi editor:
- sudo vi /etc/httpd/conf.modules.d/00-base.conf
Next, apply the configuration change by restarting Apache:
- sudo systemctl restart httpd
With Apache installed and the
mod_rewrite module enabled, we're ready to configure the use of a .htaccess file.
- sudo vi /etc/httpd/conf/httpd.conf
Locate the
<Directory /var/www/html> section and change the AllowOverride directive from None to All:
/etc/httpd/conf/httpd.conf
. . .
<Directory /var/www/html>
. . .
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
. . .
</Directory>
. . .
Save and exit the file and then restart Apache to apply the change:
- sudo systemctl restart httpd
Next, create a
.htaccess file in the default document root, /var/www/html, for Apache.
0 comments:
Post a Comment