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.
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>
<DirectoryMatch ^/srv/project/sites/(?:admin\.)?project\.hu/htdocs/$>
That seems fairly clean to me...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With