I have 2 subdomains which use the same rules, as seen below:

<Directory /srv/project/sites/project.hu/htdocs/>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)\?*$ index.php?route=$1 [L,QSA]
    SetEnv config default,local
    Order allow,deny
    allow from 192.168.0.0/16
</Directory>

<Directory /srv/project/sites/admin.project.hu/htdocs/>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)\?*$ index.php?route=$1 [L,QSA]
    SetEnv config default,local
    Order allow,deny
    allow from 192.168.0.0/16
</Directory>

As you can see the rules are the same in both containers. How can I specify these rules in a single container? At first I thought about using this:

<DirectoryMatch ^/srv/project/sites/(?:(?:admin\.project\.hu)|project\.hu)/htdocs/$>
 ...
</DirectoryMatch>

But isn't there a way to do this in a more clean way that I'm missing?

Edit: I dislike the DirectoryMatch way, because when when I'll have more directories, the regex will grow unmaintainable.

Accepted Answer

put the rewrite rules into a separate file, eg. rewrite.conf, and include it like so

<Directory /srv/project/sites/project.hu/htdocs/>
  Include rewrite.conf
</Directory>

<Directory /srv/project/sites/admin.project.hu/htdocs/>
  Include rewrite.conf
</Directory>
Written by ax
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki