Ask Your Question

Rewrite Cond|Rule inside directories with puppetlabs-apache

asked 2014-06-20 21:11:50 -0500


I'm starting to use puppetlabs-apache and I find it great. The only problem I'm having is that I need to put rewrites inside <directory> and apparently It's not possible. I tried the following and doesn't work, Puppet doesn't give any error but the rewrites aren't printed in the vhost file

apache::vhost { 
    servername      => '',  
    ip              => '',  
    port            => '80',    
    docroot         => '/path/to/document/root',
    setenv          => {'APPLICATION_ENV' => '"production"', 'DATABASE_LENGUAGE' => '"en"'},
    access_log_file => 'vhost.example.com_access.log',
    error_log_file => 'vhost.example.com_access.log',
    directories => [
      path => '/path/to/document/root/',
      directoryindex => ['index.html index.htm index.php'],
      rewrites => [
          rewrite_cond => ['%{REQUEST_FILENAME} !-f', '%{REQUEST_FILENAME} !-d', '%{REQUEST_FILENAME} !index.php'],
          rewrite_rule => ['.* /index.php [L]'],
      options => ['Indexes', 'FollowSymLinks', 'MultiViews'],
      allow_override => [ 'None' ],
      order => 'Allow,Deny',  

If I put the rewrite section outside directories it's printed in the vhost file but apache doesn't apply them. Any ideas?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-06-22 03:42:25 -0500

daff gravatar image

You can put whatever Apache configuration directives you want in the custom_fragment parameter of the directory hash if you need to do anything that is not natively supported (same goes for the custom_fragment parameter of the apache::vhost type).

Something like this might work for you:

apache::vhost { '':
  directories => [
      path => '/path/to/document/root/',
      directoryindex => ['index.html index.htm index.php'],
      options => ['Indexes', 'FollowSymLinks', 'MultiViews'],
      allow_override => [ 'None' ],
      order => 'Allow,Deny',
      custom_fragment => 'RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !index.php
        RewriteRule .* /index.php [L]'

This will put the rewrite conditions and rules at the end of the directory block. See also

edit flag offensive delete link more


Thanks Daff, We are doing that exactly but I supposed that the module was missing something, in fact I found a pull request to add the rewrites hash into directories -> so I guess a future version of the module will have it. Thanks again :D

sirgt gravatar imagesirgt ( 2014-06-23 10:27:40 -0500 )edit

This is now supported natively in the puppetlabs-apache module.

tthayer gravatar imagetthayer ( 2014-11-12 16:00:38 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-06-20 21:11:50 -0500

Seen: 2,202 times

Last updated: Jun 22 '14