I\'m working on a new server and I installed via yum the \"Web Server\" group. Php and mysql work fine but I can\'t get .htaccess to work.
Heres my test .htaccess file:<
Make sure AccessFileName set to .htaccess
Search httpd.conf for AccessFileName directive. It defines name of the distributed configuration file:
grep -i AccessFileName httpd.conf
Make sure users are allowed to use .htaccess file
What you can put in these files is determined by the AllowOverride directive. This directive specifies, in categories, what directives will be honored if they are found in a .htaccess file. If this directive is set to None, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
grep -i AllowOverride httpd.conf
When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files:
AllowOverride All
Save and close the file. Restart httpd:
service httpd restart
On CentOS7, the following should help:
/etc/httpd/conf/httpd.conf
:replace AllowOverride None to AllowOverride All
LoadModule rewrite_module modules/mod_rewrite.so
AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
AuthName "Please Enter Password"
AuthType Basic
Require valid-user
httpd -t
/bin/systemctl restart httpd.service
Have you set AllowOverride in Apache config? If not, set AllowOverride from none
to all
.
Go to /etc/httpd/conf/httpd.conf and find below line. htaccess Context is allowed in .htaccess files: AllowOverride All
Save and close the file. Restart httpd:
/etc/httpd/conf/httpd.conf:replace AllowOverride None to AllowOverride All
httpd -M | grep rewrite_module should result
rewrite_module (shared)
Still not working even after making sure all above in place? Then make sure your .htaccess has below line at the top.
RewriteEngine On