# can't enable mod_rewrite in Apache2 [solved]

## odioworks_com

I just emerged apache2, and the .htacess file that I had on my previous server (which used mod_rewrite) no longer works.

I load the module in httpd.conf:

```
LoadModule rewrite_module                modules/mod_rewrite.so
```

I also changed "AllowOverride" to "All" in httpd.conf (not sure if this is needed...):

```
<Directory />

    Options FollowSymLinks

#    AllowOverride None

    AllowOverride All

</Directory>
```

When I run apache2ctl -l this is what is returned (not sure if this means anything):

```
Compiled in modules:

  core.c

  prefork.c

  http_core.c

  mod_so.c
```

This is my .htacess in my root directory:

```
RewriteEngine On

Options +FollowSymlinks

RewriteRule ^(.*)-(.*).html$ index.php?pid=$1&pageTitle=$2
```

http://www.odioworks.com/index.php?pid=32&pageTitle=An_Entrepreneur_Scholarship works, while

http://www.odioworks.com/32-An_Entrepreneur_Scholarship.html (which should work) doesn't.Last edited by odioworks_com on Sun May 28, 2006 4:09 pm; edited 1 time in total

----------

## odioworks_com

nobody?  I've been googling for two days and still can't figure this out... if anyone has any hunch at all about what I'm doing let me know!

----------

## lxg

 *Quote:*   

> I also changed "AllowOverride" to "All" in httpd.conf (not sure if this is needed...)

 

AllowOverride All and FollowSymLinks are mandatory for mod_rewrite.

But: Are you sure mod_rewrite is broken? Or can it be that you've set up faulty rewrite rules?

Usually, when there's a problem with the server's configuration, you'll get an HTTP 500 for the entire (virtual) host.

----------

## odioworks_com

[quote="lx0"] *Quote:*   

> 
> 
> But: Are you sure mod_rewrite is broken? Or can it be that you've set up faulty rewrite rules?
> 
> Usually, when there's a problem with the server's configuration, you'll get an HTTP 500 for the entire (virtual) host.

 

Normally, I would think that I configured faulty rewrite rules.  But I'm perplexed because the rules worked on my previous server.

this is my .htaccess file (trimmed to most important rule):

```
RewriteEngine On

Options +FollowSymlinks

RewriteBase /

RewriteRule ^(.*)-(.*).html$ index.php?pid=$1&pageTitle=$2
```

This should rewrite 10-Page_Title.html to index.php?pid=10&pageTitle=Page_Title

thanks for your help man.

----------

## lxg

Holy Moses, I'm no big mod_rewrite guru at all. I usually take apps that'll create the rewrite rules for me.  :Wink: 

But some ideas that might be worth considering:

- Have you migrated to another Apache series (e.g. 1.3 -> 2.0)? AFAIK the rewrite rules set has changed between the versions.

- IIRC you need to use %{QUERY_STRING} and/or [QSA] when matching against parts of the query string. (Please see the Apache docs.)

Another idea: You could try to determine whether your rewrite engine runs by creating a .htaccess with the following code: 

```
<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>
```

(courtesy of WordPress)

Then enter an obviously false URL; if you are then redirected to your index.php, you can be sure the rewrite engine works.

----------

## odioworks_com

 *lx0 wrote:*   

> Holy Moses, I'm no big mod_rewrite guru at all. I usually take apps that'll create the rewrite rules for me. 
> 
> But some ideas that might be worth considering:
> 
> - Have you migrated to another Apache series (e.g. 1.3 -> 2.0)? AFAIK the rewrite rules set has changed between the versions.
> ...

 

Nope, migrated apache2 to apache2.  None of the rewrite rules work, even the ones that don't match query strings.

 *lx0 wrote:*   

> Another idea: You could try to determine whether your rewrite engine runs by creating a .htaccess with the following code: 
> 
> ```
> <IfModule mod_rewrite.c>
> 
> ...

 

Looks like the engine is not running, since after making this the .htaccess file I'm not redirected to index.php.

Thanks again for your help...

----------

## lxg

 *odioworks_com wrote:*   

> Looks like the engine is not running, since after making this the .htaccess file I'm not redirected to index.php

 

Well, then let's investigate: Could you append -e debug to your APACHE2_OPTS in /etc/conf.d/apache2? Then restart apache and post the output, please.

What does /var/log/apache2/error_log say?

----------

## odioworks_com

This is an excerpt from my error log.  The line occurred when I tried to access test1234 (which didn't exist).

```
[Sat May 27 08:01:23 2006] [error] [client 68.98.189.198] File does not exist: /var/www/odioworks-com/htdocs/test1234
```

apache output

```
[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module access_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module auth_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module auth_anon_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module auth_dbm_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module auth_digest_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module charset_lite_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module env_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module expires_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module headers_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module mime_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module negotiation_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module setenvif_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module log_config_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module logio_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module cgi_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module cgid_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module suexec_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module alias_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module rewrite_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module actions_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module autoindex_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module dir_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module ext_filter_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module deflate_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module include_module

[Sat May 27 08:05:26 2006] [debug] mod_so.c(248): loaded module ssl_module

[Sat May 27 08:05:27 2006] [debug] mod_so.c(248): loaded module php5_module
```

FYI, here's my httpd.conf:

http://www.odioworks.com/httpd.conf

I also enabled apache's rewrite log.  I've uploaded that here:

http://www.odioworks.com/rewrite_log

----------

## lxg

Well, strange... mod_rewrite appears to be loaded, and I can't see any obvious from the other files you posted, either.

Have you changed anything in the httpd.conf? If so, would it help to restore the original file?

How are your virtual hosts set up? Could you post the vhost configuration file for the above domain? This is also a possible source of hassle.

Or have you done some heavy emerging? If so, what does revdep-rebuild -pv say?

----------

## odioworks_com

 *lx0 wrote:*   

> Well, strange... mod_rewrite appears to be loaded, and I can't see any obvious from the other files you posted, either.
> 
> Have you changed anything in the httpd.conf? If so, would it help to restore the original file?
> 
> How are your virtual hosts set up? Could you post the vhost configuration file for the above domain? This is also a possible source of hassle.
> ...

 

Restored the original httpd.conf file and disabled vhosts.  After changing "AllowOverride None" to "AllowOverride All" the redirect works.

You're right, it seems vhosts is causing the problems.  When I enable the line:

```
Include /etc/apache2/vhosts.d/*.conf
```

in httpd.conf, mod_rewrite breaks.  Any ideas?

----------

## odioworks_com

Figured it out:

in each of the the vhost conf files change:

```
AllowOverride None
```

to:

```
AllowOverride All
```

Should've caught that earlier...

----------

## axlotl

 *Quote:*   

> Figured it out:
> 
> in each of the the vhost conf files change:
> 
> Code:
> ...

 

T H A N K   Y O U.

..for taking solving a source of endless annoying workarounds.

----------

## Oblong_Cheese

THANK-YOU!!!!!

I was having this problem as well with my Wordpress blog (permalinks not working using mod_rewrite) and was tearing my hair out trying to fix it!

THANKS!

----------

## tessmonsta

ThankyouThankyouThankyou!

I was having the same problem with Drupal 4.7. Now it's all fixed!   :Very Happy: 

----------

## zietbukuel

This doesn't work for me  :Sad:  apache is crazy it is looking for some "home" & "htdocs" files, see:

```
[Mon Oct 09 23:52:21 2006] [error] [client 127.0.0.1] File does not exist: /usr/htdocs, referer: http://bavrit.eth0.ws/~ziet/Portal/

```

(this is without vhosts)

```
[Mon Oct 09 23:56:38 2006] [error] [client 127.0.0.1] File does not exist: /var/www/localhost/htdocs/home, referer: http://bavrit.eth0.ws/~ziet/Portal/
```

(This is with vhosts enabled)

I have:

AllowOverride All

And mod_ewrite enabled, what is wrong?? if you need more info about my config, just ask, please, thank you.

Apache thinks "/usr/lib/apache/htdocs" is "/" wtf?

ps. im using apache-1.3, i have the same with apache-2.0...   :Confused: 

----------

