To verify mod_rewrite is enabled in your Apache server, run
On CentOS
[root@server1 ~]# httpd -M | grep rewrite rewrite_module (shared) [root@server1 ~]#
On Debian/Ubuntu
root@ip-172-31-24-50:~# apachectl -M | grep rewrite rewrite_module (shared) root@ip-172-31-24-50:~#
If the command shows “rewrite_module”, you have rewrite module enabled on your Apache server.
On CentOS servers, rewrite module is enabled by default. On Ubuntu/Debian, you need to enable it with command
sudo a2enmod rewrite sudo service apache2 restart
Enabling htaccess for your web site
To enable rewrite module for your web site, you need to add
AllowOverride All
In your VirtualHost entry.
Here is a sample virtual host entry i use on Ubuntu server.
<VirtualHost 127.0.0.1:80> ServerName blog.hostonnet.com ServerAdmin [email protected] DocumentRoot /home/blog.hostonnet.com/public_html CustomLog ${APACHE_LOG_DIR}/blog.hostonnet.com.log combined <Directory "/home/blog.hostonnet.com/public_html"> Options All AllowOverride All Require all granted Order allow,deny allow from all </Directory> </VirtualHost>
On CentOS server, default web site don’t have .htaccess enabled by default. To enable, edit httpd.conf
vi /etc/httpd/conf/httpd.conf
Find
<Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # 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 None # # Controls who can get stuff from this server. # Require all granted </Directory>
Change
AllowOverride None
to
AllowOverride All
You need to restart apache with
On CentOS
service httpd restart
On Debian/Ubuntu
service apache2 restart