.htaccess: RewriteEngine not allowed here

Hi all,

I have a dedicated server supplied by Fasthosts, that runs Fedora Core 3. Its an odd setup - the server runs Fasthosts’ “Matrix Control Panel”. Apache has a central config file (httpd.conf) and then the sites that are hosted on the server are listed in vhost.conf. The base settings are set in the httpd.conf I guess, and then overidden in vhost.conf, and then overidden some more in .htaccess.

I am having problems trying to get any mod_rewriting to work. As soon as I turn “RewriteEngine On”, I get a 500 internal server error. I look in the error log, and see “.htaccess: RewriteEngine not allowed here”. I guess there must be something wrong with my Apache setup - can anyone give me an idea as to what it might be?

I’ll copy in the important parts of each file below (with personal info omitted):


LoadModule rewrite_module modules/mod_rewrite.so

<Directory />
    Options FollowSymLinks
    AllowOverride AuthConfig Indexes

<Directory "/var/www/html">
    Options All
    AllowOverride All
    Order allow,deny
    Allow from all

AccessFileName .htaccess

# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
<Files ~ "^\\.ht">
    Order allow,deny
    Deny from all


Listen 80
ServerRoot "/etc/httpd"
<IfModule mod_dir.c>
    DirectoryIndex default.html default.htm index.html index.htm index.shtml     index.php index.php4$

<VirtualHost [ip_address]:80 [ip_address]:80>
        ServerName [domain_name]
        ServerAlias [domain_name]
        ServerAdmin webmaster@[domain_name]
        DocumentRoot /home/default/[domain_name]/user/htdocs
        ErrorLog /home/default/[domain_name]/user/logfiles/error_log
        TransferLog /home/default/[domain_name]/user/logfiles/access_log
        php_admin_value open_basedir /tmp:/home/default/[domain_name]
        ErrorDocument 404 /errors/404.php
        SuexecUserGroup [domain_name] matrixdomain
        AddHandler server-parsed .shtml
        AddType text/html .shtml
        <Location />
                #Options +Includes
                #Options All
                Options +FollowSymLinks
        # AC
        <Directory /home/default/[domain_name]/user/htdocs/>
                #AllowOverride AuthConfig Limit Indexes
                AllowOverride All
                Options +FollowSymLinks
# Begin user directives <--
# --> End user directives


RewriteEngine On
RewriteBase /
RewriteLog "/home/default/[domain_name]/user/htdocs/rewrite.log"
RewriteLogLevel 7
RewriteRule ^/portfolio/view/([0-9]*)/$ /portfolio/view.php?ID=$1

I am wanting to turn “/portfolio/view.php?id=3” into “/portfolio/view/4/”. However, even simple rules don’t work such as changing test.html into test.php (follow a tutorial here: http://www.datakoncepts.com/seo).

Anything glaringly obvious in my setup?


Apache manual to the rescue!

RewriteLog Directive
Description:	Sets the name of the file used for logging rewrite engine processing
Syntax:	RewriteLog file-path
[b]Context:	server config, virtual host[/b]
Status:	Extension
Module:	mod_rewrite

RewriteLogLevel Directive
Description:	Sets the verbosity of the log file used by the rewrite engine
Syntax:	RewriteLogLevel Level
Default:	RewriteLogLevel 0
[b]Context:	server config, virtual host[/b]
Status:	Extension
Module:	mod_rewrite

Why would you want to use .htaccess anyway? It’s slow and should only be used if you have no access to virtual host and server config.

Thanks for the reply - i have put the RewriteLog directives in my .htaccess, as shown in my first post. However, it is when the RewriteEngine is turned on that I get the errors - thus, no log is ever created/updated.

I want to use .htaccess as I have multiple sites running on the same server, and want to be as flexible as possible with how I configure them.


Maybe you misunderstood. RewriteLog cannot be used in .htaccess. It can only go in server config or virtual host. Of course it is only activated when you turn RewriteEngine On.

I have multiple sites running on the same server, and want to be as flexible as possible with how I configure them.

So does everyone, but the directives should go straight into virtual host config instead.

.htaccess is read from disk everytime someone loads a page and makes it much slower. It is only made for people who are on shared hosting and have no access to higher level. If you have root access, avoid using it. Virtual host and server config are read into memory as apache starts up, so they are much faster options.