developemt,分期和生产之间的.htaccess [英] .htaccess between developemt, staging, and production

查看:300
本文介绍了developemt,分期和生产之间的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用URL重写,并具有特定的.htaccess配置一个应用程序。在应用程序工作时,我有三个eviorments:

  1. 在Developent我的本地机器(本地主机)
  2. 在分期(staging.mydomain.com)
  3. 生产(www.mydomain.com)

我不断推新升级的分期和生产环境和每个I覆盖现有的源$ C ​​$ C时候我已经在改走.htaccess文件。有没有一种方法可以让我在通用的.htaccess的目录,或者对其进行自动侦测到它的环境?

我目前的.htaccess文件如下。我只是取消注释的部分不同的环境之间,但希望能停止这样做......

 #开发

RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!= /的favicon.ico
重写规则^(。*)$ /app/index.php?request=$1 [L,QSA]

#分期

#RewriteEngine叙述上
#的RewriteCond%{} REQUEST_FILENAME!-f
#的RewriteCond%{} REQUEST_FILENAME!-d
#的RewriteCond%{REQUEST_URI}!= /的favicon.ico
#重写规则^(。*)$ /html/app/index.php?request=$1 [L,QSA]

#生产

#RewriteEngine叙述上
#的RewriteCond%{} REQUEST_FILENAME!-f
#的RewriteCond%{} REQUEST_FILENAME!-d
#的RewriteCond%{REQUEST_URI}!= /的favicon.ico
#重写规则^(。*)$ /index.php?request=$1 [L,QSA]
 

在此先感谢!

解决方案

 #开发

RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!= /的favicon.ico
的RewriteCond%{REQUEST_HOST} ^本地主机
重写规则^(。*)$ /app/index.php?request=$1 [L,QSA]

#分期

RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!= /的favicon.ico
的RewriteCond%{REQUEST_HOST} ^ staging.mydomain.com
重写规则^(。*)$ /html/app/index.php?request=$1 [L,QSA]

#生产

RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!= /的favicon.ico
的RewriteCond%{REQUEST_HOST} ^ www.mydomain.com
重写规则^(。*)$ /index.php?request=$1 [L,QSA]
 

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 local machine (localhost)
  2. Staging (staging.mydomain.com)
  3. Production (www.mydomain.com)

I am constantly pushing new upgrades to the staging and production environment and each time I overwrite the existing source code I have to go in an change the .htaccess file. Is there a way I can the .htaccess generic to the directory or have it automatically detect it's environment?

My current .htaccess file is below. I just un-comment the sections between the different environments but would love to stop doing that...

# Development

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ /app/index.php?request=$1 [L,QSA]

# Staging

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

# Production

# RewriteEngine on
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !=/favicon.ico
# RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]

Thanks in advance!

Chuck

解决方案

# Development

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_HOST} ^localhost
RewriteRule ^(.*)$ /app/index.php?request=$1 [L,QSA]

# Staging

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_HOST} ^staging.mydomain.com
RewriteRule ^(.*)$ /html/app/index.php?request=$1 [L,QSA]

# Production

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_HOST} ^www.mydomain.com
RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]

这篇关于developemt,分期和生产之间的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆