3
votes

I'm trying to enable the rewrite function in drupal 7 without using the .htaccess file since it should only be used if you do not have root access to the server (accordingly to apache's website)

Without any further adieu, here is my configuration

<VirtualHost *:80>
  ServerName  www.example.com
  ServerAlias example.com

  DirectoryIndex index.php
  DocumentRoot /var/www/example.com/public

  ErrorDocument 404 /index.php

  LogLevel warn
  ErrorLog  /var/www/example.com/log/error.log
  CustomLog /var/www/example.com/log/access.log combined

  <Directory "/var/www/example.com/public">
    Options -Indexes +FollowSymLinks +ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
  </Directory>
</VirtualHost>

The rewrite configuration worked when I had it in the .htaccess file but not when I put it inside the vhost file.

Can you guys see anything wrong here?

1

1 Answers

1
votes

I think your rewrite rule should not contain the '/' prefix now that it's not a .htaccess anymore. Soo try with:

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Removing .htaccess reference is a good idea. You should put the AllowOverride None on a <Directory /> instruction so that this start from the root of the filesystem. If think you do not need the +ExecCGI also. If you want to go deeper in apache config for Drupal without .htaccess check also this detailled resource.