Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable mod_rewrite on Apache 2.4?

I'm using Wordpress and wanted to enable pretty urls feature, but they don't work, i'm thinking that it's because of mod_rewrite, but i don't know how to enable it on Apache 2.4 under CentOS 7...

I've already try this:

grep -i LoadModule /etc/httpd/conf/httpd.conf | grep rewrite

but nothing... Also would like to know it loading all Apache modules has any bad consequence or is it bad practice?

like image 659
Jonathan Solorzano Avatar asked Jun 15 '15 21:06

Jonathan Solorzano


People also ask

How do I enable a2enmod?

In order for Apache to understand rewrite rules, we first need to activate mod_rewrite . It's already installed, but it's disabled on a default Apache installation. Use the a2enmod command to enable the module: sudo a2enmod rewrite.

What is Apache mod_rewrite?

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. Incoming URLs are checked against a series of rules. The rules contain a regular expression to detect a particular pattern.


3 Answers

I found the way to know if a module is loaded or not, here's to command to list the modules enabled:

apachectl -M | sort

It will list all enabled modules alphabetically.

Wordpress has an .htaccess but default where it enables rewrite_module for its use:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

The only thing that i had to do was add this to the vhost.conf file at /etc/httpd/conf.d/vhosts.conf

<Directory /var/www/mysite>
    Options Indexes FollowSymLinks
    Require all granted
    AllowOverride All
</Directory>

That's because I'm handling my hosts in that file. But it could be done at httpd.conf, or any other .conf file that is Included to the httpd.conf

Thanks...

like image 71
Jonathan Solorzano Avatar answered Sep 24 '22 05:09

Jonathan Solorzano


Apache2 ships with executables a2enmod and a2dismod that will do all the "dirty work" of symlinking conf files.

On Debian based distros, the usual location is /etc/apache/mods-available/. Here are the .conf configuration files (when applicable) and a .load file per module with the LoadModule Apache2 directive. A module is enabled if there is a symlink to its .load file in the /etc/apache2/mods-enabled/.

You would, for example, enable the Rewrite module with command

$ a2enmod rewrite
like image 22
marekful Avatar answered Sep 20 '22 05:09

marekful


# nano /etc/httpd/conf/httpd.conf

find

follow (AllowOverride none) 

and change it

(AllowOverride All) 
like image 23
reimi Avatar answered Sep 23 '22 05:09

reimi