Skip to content

Instantly share code, notes, and snippets.

@k-holy
Last active February 21, 2021 21:17
Show Gist options
  • Save k-holy/6632237 to your computer and use it in GitHub Desktop.
Save k-holy/6632237 to your computer and use it in GitHub Desktop.
Dynamic RewriteBase for Apache (mod_rewrite, mod_setenvif)
RewriteEngine On
#----------------------------------------------------------
# RewriteBase for develop
#----------------------------------------------------------
# SetEnvIf
SetEnvIf Host ^develop.example.com$ REWRITE_BASE=/path/to/develop
# or RewriteCond
#RewriteCond %{HTTP_HOST} ^develop.example.com$
#RewriteRule . - [E=REWRITE_BASE:/path/to/develop]
#----------------------------------------------------------
# RewriteBase for staging
#----------------------------------------------------------
# SetEnvIf
SetEnvIf Host ^staging.example.com$ REWRITE_BASE=/path/to/staging
# or RewriteCond
#RewriteCond %{HTTP_HOST} ^staging.example.com$
#RewriteRule . - [E=REWRITE_BASE:/path/to/staging]
#----------------------------------------------------------
# RewriteBase for production
#----------------------------------------------------------
# SetEnvIf
SetEnvIf Host ^www.example.com$ REWRITE_BASE=/path/to/production
# or RewriteCond
#RewriteCond %{HTTP_HOST} ^www.example.com$
#RewriteRule . - [E=REWRITE_BASE:/path/to/production]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.(ico|gif|jpe?g|png|css|js)$ [NC]
RewriteRule ^(.*)$ %{ENV:REWRITE_BASE}/index.php [QSA,NS,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment