Preventing RewriteBase - Deploy websites and apps on different locations

So I found a topic on stackexchange (for which unfortunately I can not find the link anymore) that had a question if it was possible to set up RewriteRules for sites in subdirectories. I found this to be an interesting topic, since I deal a lot with those kind of sites.

I have my development set up to serve sites as /projects/{project_name}, my testing server as /testing/{client}/{project_name}, and production sites all live in the document root of company domains.

The way this can be done is to use RewriteCond:

# append %{ENV:REWRITE_BASE} to rules.
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=REWRITE_BASE:%1]

Now, to redirect every request that is not a file to index.php in the directory where .htaccess resides:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:REWRITE_BASE}index.php/$1 [QSA,L]

This works perfectly :)

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *