# mod_rewrite fails after update to new apache config [SOLVED]

## m27315

I was running a phpBB forum on my Gentoo box, and decided to upgrade to new version of Apache with the new httpd.conf config setup.  I merged all of my config files into httpd.conf, vhosts.d dir, and modules.d dir, and everything else seems to be working fine, except mod_rewrite.  For some crazy reason, I cannot seem to be able to coax this latest version of apache2 to read my rewrite rules in the site's .htaccess file.

Does anybody have any guesses?

Here's the releavant snippets from the config files, at least I think they are releavant:

Load the module here...

httpd.conf:

```
...

#

# Mappers

#

# These Modules provide URL mappings or translations.

LoadModule alias_module                  modules/mod_alias.so

LoadModule rewrite_module                modules/mod_rewrite.so

<IfDefine USERDIR>

    LoadModule userdir_module            modules/mod_userdir.so

</IfDefine>

...

<Directory />

  Options -All -Multiviews

  AllowOverride All

  <IfModule mod_access.c>

    Order deny,allow

    Deny from all

  </IfModule>

</Directory>

...
```

Open up public read and .htaccess override here...

vhosts.d/vhosts.conf:

```
NameVirtualHost *:80

NameVirtualHost *:8080

...

<VirtualHost *:80>

ServerName myserver

ServerPath /myserver

DocumentRoot /var/www/myserver/htdocs

<Directory /var/www/myserver/htdocs>

   Options -Indexes FollowSymLinks MultiViews

   AllowOverride All

   <IfModule mod_access.c>

       Order allow,deny

       Allow from all

  </IfModule>

</Directory>

...
```

Include rewrite rules here...

/var/www/myserver/htdocs/.htaccess:

```
# Craven de Kere's rewrite rules for phpBB

RewriteEngine On

RewriteRule ^forums.* index.php [L,NC]

RewriteRule ^post-([0-9]*).html&highlight=([a-zA-Z0-9]*) viewtopic.php?p=$1&highlight=$2 [L,NC]

RewriteRule ^post-([0-9]*).* viewtopic.php?p=$1 [L,NC]

RewriteRule ^view-poll([0-9]*)-([0-9]*)-([a-zA-Z]*).* viewtopic.php?t=$1&postdays=$2&postorder=$3&vote=viewresult [L,NC]

RewriteRule ^about([0-9]*).html&highlight=([a-zA-Z0-9]*) viewtopic.php?t=$1&highlight=$2 [L,NC]

RewriteRule ^about([0-9]*).html&view=newest viewtopic.php?t=$1&view=newest [L,NC]

RewriteRule ^about([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*).* viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4 [L,NC]

RewriteRule ^about([0-9]*)-([0-9]*).* viewtopic.php?t=$1&start=$2 [L,NC]

RewriteRule ^about([0-9]*).* viewtopic.php?t=$1 [L,NC]

RewriteRule ^about([0-9]*).html viewtopic.php?t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5 [L,NC]

RewriteRule ^mark-forum([0-9]*).html* viewforum.php?f=$1&mark=topics [L,NC]

RewriteRule ^updates-topic([0-9]*).html* viewtopic.php?t=$1&watch=topic [L,NC]

RewriteRule ^stop-updates-topic([0-9]*).html* viewtopic.php?t=$1&unwatch=topic [L,NC]

RewriteRule ^forum-([0-9]*).html viewforum.php?f=$1 [L,NC]

RewriteRule ^forum-([0-9]*).* viewforum.php?f=$1 [L,NC]

RewriteRule ^topic-([0-9]*)-([0-9]*)-([0-9]*).* viewforum.php?f=$1&topicdays=$2&start=$3 [L,NC]

RewriteRule ^ptopic([0-9]*).* viewtopic.php?t=$1&view=previous [L,NC]

RewriteRule ^ntopic([0-9]*).* viewtopic.php?t=$1&view=next [L,NC]
```

What am I missing?  This used to work, but now I'm broke...   :Sad: Last edited by m27315 on Fri Sep 23, 2005 9:55 pm; edited 1 time in total

----------

## Pasketti

I had the same problem.

I had to move the rules into /etc/apache2/vhosts.d/00_default_vhost.conf, and then it started working.

When I find time, I'm going to disable vhosts.

----------

## m27315

 :Shocked:  Aieeeeee!!!   :Evil or Very Mad:    What a stupid mistake I made!!! <insert sound of head banging against wall></sound>

Here was my problem.  I have no idea why I changed this in the first place, but in the new httpd.conf file, I erroneously had this:

```
AccessFileName /etc/apache2/.htaccess
```

This made apache look for the wrong local modifier file!  So, it couldn't find any rules in my .htaccess file.  There were no errors in my /var/log/apache2/error_log, so I didn't have any clues.  I had to take a fresh look at the config file this morning, and when I did, it smacked me in the face.  So, to sum up, here's the relevant snippets I have for a virtual host setup, using mod_rewrite, which now works  for me:

/etc/apache2/httpd.conf:

```
ServerRoot "/usr/lib/apache2"

...

LoadModule rewrite_module                modules/mod_rewrite.so

...

<Directory />

  Options -All -Multiviews

  AllowOverride None

  <IfModule mod_access.c>

    Order deny,allow

    Deny from all

  </IfModule>

</Directory>

...

AccessFileName .htaccess

...

<Files ~ "^\.ht">

    Order allow,deny

    Deny from all

</Files>

...

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

The last line loads my one and only config file in the vhosts.d directory, /etc/apache2/vhosts.d/vhosts.conf:

```
NameVirtualHost *:80

NameVirtualHost *:8080

<VirtualHost *:80>

   ServerName mydomainname

   ServerPath /mydomainname

   DocumentRoot /var/www/mydomainname/htdocs

   <Directory /var/www/mydomainname/htdocs>

      Options -Indexes FollowSymLinks MultiViews

      AllowOverride All

      <IfModule mod_access.c>

          Order allow,deny

          Allow from all

     </IfModule>

   </Directory>

</VirtualHost>

...
```

/var/www/mydomainname/htdocs/.htaccess:

```
# Craven de Kere's rewrite rules for phpBB

RewriteEngine On

RewriteRule ^forums.* index.php [L,NC]

RewriteRule ^post-([0-9]*).html&highlight=([a-zA-Z0-9]*) viewtopic.php?p=$1&highlight=$2 [L,NC]

RewriteRule ^post-([0-9]*).* viewtopic.php?p=$1 [L,NC]

RewriteRule ^view-poll([0-9]*)-([0-9]*)-([a-zA-Z]*).* viewtopic.php?t=$1&postdays=$2&postorder=$3&vote=viewresult [L,NC]

RewriteRule ^about([0-9]*).html&highlight=([a-zA-Z0-9]*) viewtopic.php?t=$1&highlight=$2 [L,NC]

RewriteRule ^about([0-9]*).html&view=newest viewtopic.php?t=$1&view=newest [L,NC]

RewriteRule ^about([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*).* viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4 [L,NC]

RewriteRule ^about([0-9]*)-([0-9]*).* viewtopic.php?t=$1&start=$2 [L,NC]

RewriteRule ^about([0-9]*).* viewtopic.php?t=$1 [L,NC]

RewriteRule ^about([0-9]*).html viewtopic.php?t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5 [L,NC]

RewriteRule ^mark-forum([0-9]*).html* viewforum.php?f=$1&mark=topics [L,NC]

RewriteRule ^updates-topic([0-9]*).html* viewtopic.php?t=$1&watch=topic [L,NC]

RewriteRule ^stop-updates-topic([0-9]*).html* viewtopic.php?t=$1&unwatch=topic [L,NC]

RewriteRule ^forum-([0-9]*).html viewforum.php?f=$1 [L,NC]

RewriteRule ^forum-([0-9]*).* viewforum.php?f=$1 [L,NC]

RewriteRule ^topic-([0-9]*)-([0-9]*)-([0-9]*).* viewforum.php?f=$1&topicdays=$2&start=$3 [L,NC]

RewriteRule ^ptopic([0-9]*).* viewtopic.php?t=$1&view=previous [L,NC]

RewriteRule ^ntopic([0-9]*).* viewtopic.php?t=$1&view=next [L,NC]
```

Of course, after making all of these changes, I had to restart apache:

```
/etc/init.d/apache2 restart
```

That did it!  Everything works great now.  Oh well, maybe this will help somebody else...

FYI, just in case your curious, all of this is being done to implement one of Craven de Kere's Search Engine Optimiazation (SEO) tricks by rewriting the funky php URL's into search-engine friendly HTML-posing URL's:

http://www.able2know.com/forums/about15132.html

Works great for me!

----------

