How do you enable mod_rewrite on any OS?
If I understand correctly, I need to put something in httpd.config
to enable mod_rewrite. If this is true, what do I need to put in httpd.conf
or apache.conf
? Please be OS specific.
Nope, mod_rewrite
is an Apache module and has nothing to do with PHP.
To activate the module, the following line in httpd.conf
needs to be active:
LoadModule rewrite_module modules/mod_rewrite.so
to see whether it is already active, try putting a .htaccess
file into a web directory containing the line
RewriteEngine on
if this works without throwing a 500 internal server error, and the .htaccess
file gets parsed, URL rewriting works.
Just a fyi for people enabling mod_rewrite on Debian with Apache2:
To check whether mod_rewrite is enabled:
Look in mods_enabled for a link to the module by running
ls /etc/apache2/mods-enabled | grep rewrite
If this outputs rewrite.load
then the module is enabled. (Note: your path to apache2 may not be /etc/, though it's likely to be.)
To enable mod_rewrite if it's not already:
Enable the module (essentially creates the link we were looking for above):
a2enmod rewrite
Reload all apache config files:
service apache2 restart
In my case, issue was occured even after all these configurations have done (@Pekka has mentioned changes in httpd.conf & .htaccess files). It was resolved only after I add
<Directory "project/path">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
to virtual host configuration in vhost file
Edit on 29/09/2017 (For Apache 2.4 <) Refer this answer
<VirtualHost dropbox.local:80>
DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"
ServerName dropbox.local
ErrorLog "logs/dropbox.local-error.log"
CustomLog "logs/dropbox.local-access.log" combined
<Directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs">
# AllowOverride All # Deprecated
# Order Allow,Deny # Deprecated
# Allow from all # Deprecated
# --New way of doing it
Require all granted
</Directory>