How to Enable mod_rewrite on Apache on CentOS

How to Enable mod_rewrite on Apache on CentOS

Link to The Lady Programmer

How to Enable mod_rewrite on Apache on CentOS

Posted: 16 Dec 2013 07:50 AM PST

Infamous 404 Server ErrorEver encountered the problem where you get 404 error when you use pretty permalinks in your WordPress blog? Like, the homepage loads up nicely  but other pages of the sites all return 404 error page?

Most likely mod_rewrite is not enabled on the Apache server.

I have encountered this earlier on my CentOS server and here is where you need to do the fixes. You need to execute the commands as root.

  1. Edit the httpd.conf file. This is the file where Apache settings for startup and operation (hence, the extension .conf) are placed. In CentOS, the file is located in this folder /etc/httpd/conf. I use either the command line editor vi or gedit, but other text editors work Editor
    # vi /etc/httpd/conf/httpd.conf


    # gedit /etc/httpd/conf/httpd.conf
  2. Find this line and uncomment it by removing the “#” before this line. So,
    #LoadModule rewrite_module modules/


    LoadModule rewrite_module modules/

    Don’t forget to save the file.

  3. Restart the Apache server.
    # service httpd restart
  4. See if you can now navigate – if you can, then you do not need to continue following the steps below.
  5. Go to DocumentRoot directive, usually written as <Directory “/var/www”>. Change the line below it that says AllowOverride None to AllowOverride All
  6. Go ahead and restart the server once again. The pretty permalinks should now work.