.htaccess between developemt, staging, and production

前端 未结 4 2208
予麋鹿
予麋鹿 2020-12-28 17:55

I\'m working on a app that uses url rewrites and has a specific .htaccess configuration. When working on the app I have three eviorments:

  1. Developent on my loca
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-28 18:27

    One option would be to setup environment variables in httpd.conf (or elsewhere) that define your environment.

    For example (in httpd.conf):

    SetEnv ENVIRONMENT production
    

    (in .htaccess)

    RewriteEngine on
    
    # Development
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} != /favicon.ico
    RewriteCond %{ENV:ENVIRONMENT} = development
    RewriteRule ^(.*)$ /app/index.php?request=$1 [L,QSA]
    
    # Staging
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} != /favicon.ico
    RewriteCond %{ENV:ENVIRONMENT} = staging
    RewriteRule ^(.*)$ /html/app/index.php?request=$1 [L,QSA]
    
    # Production
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} != /favicon.ico
    RewriteCond %{ENV:ENVIRONMENT} = production
    RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]
    

    Untested, but I think the concept is sound enough to figure out any issues ;-)

提交回复
热议问题