50

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.

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
John
  • 4,820
  • 21
  • 62
  • 92

8 Answers8

67

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.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Thanks... how do I tell if the .htaccess file is getting parsed? – John Jun 28 '10 at 09:54
  • 2
    @John you usually can't activate mod_rewrite yourself on shared hosting: It's up to the hosting company to do so. Try `RewriteEngine` to see whether it maybe already is active - if it isn't, you're going to have to talk to them. – Pekka Jun 28 '10 at 09:54
  • @John re your updated comment: Write something like `asdfasdf` into the file. That should land you a `500 internal server error`. – Pekka Jun 28 '10 at 09:55
  • Yeah, okay. It is getting parsed. I still can get even a simple ReWrite to work, though. – John Jun 28 '10 at 10:03
  • @John does it accept `RewriteEngine On` without errors? If it does, the problem is with your rewrite statement. Maybe worth a new question. – Pekka Jun 28 '10 at 10:04
61

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
FarmerGedden
  • 1,162
  • 10
  • 23
13

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>

Sadee
  • 3,010
  • 35
  • 36
2

No, you should not need to. mod_rewrite is an Apache module. It has nothing to do with php.ini.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jason Lewis
  • 18,537
  • 4
  • 61
  • 64
1

if it related to hosting site then ask to your hosting or if you want to enable it in local machine then check this youtube step by step tutorial related to enabling rewrite module in wamp apache https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp server icon -> Apache -> Apache Modules and check the rewrite module option it should be checked but after that wamp require restart all services

Hassan Saeed
  • 6,326
  • 1
  • 39
  • 37
0

network solutions offers the advice to put a php.ini in the cgi-bin to enable mod_rewrite

  • I've heard this, too, but I think it's false. I recommend just checking the syntax of your .htaccess file to screen out any errors. Pretty much any server, including Netsol's, that run Apache have mod_rewrite enabled by default. – goddogsrunning Apr 05 '13 at 20:45
0

Module rewrite_module is built-in in to the server most cases

Use .htaccess

Use the Mod Rewrite Generator at http://www.generateit.net/mod-rewrite/

jjnguy
  • 136,852
  • 53
  • 295
  • 323
  • 1
    This answer is not clarifying. If OP is asking how to enable something, you're expected to assume it's disabled. – Gui Imamura Jul 16 '15 at 18:33
-3

In order to use mod_rewrite you can type the following command in the terminal:

 $ su

 $ passwd **********

 # a2enmod rewrite

Restart apache2 after

 # service apache2 restart

 # /etc/init.d/apache2 restart

or

 # service apache2 restart
Flexo
  • 87,323
  • 22
  • 191
  • 272
JItendra
  • 1
  • 2