tags:

views:

209

answers:

2

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.

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

That seems fairly clean to me...

David Zaslavsky
+2  A: 

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>
ax
Thank you, that's what I was looking for!
WishCow