Kohana3:不同的.htaccess的RewriteBase和Kohana的BASE_URL用于开发和生产环境 [英] Kohana3: Different .htaccess rewritebase and kohana base_url for dev and production environment

查看:376
本文介绍了Kohana3:不同的.htaccess的RewriteBase和Kohana的BASE_URL用于开发和生产环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 bootstrap.php中我有以下几点:

if($_SERVER['SERVER_NAME'] == 'localhost')
    Kohana::$environment = 'development';
else
    Kohana::$environment = 'production';

...

switch(Kohana::$environment)
{
    case 'development':
        $settings = array('base_url' => '/kohana/', 'index_file' => FALSE);
        break;

    default:
        $settings = array('base_url' => '/', 'index_file' => FALSE);
        break;
}

的.htaccess 有这样的:

# Installation directory
RewriteBase /kohana/

这意味着,如果我刚刚上传我的Kohana的应用程序,这将打破,因为在的.htaccess 文件中的RewriteBase将是错误的。有没有一种方法可以让我有一个条件的的.htaccess 文件类似于一个我的引导,使其使用正确的RewriteBase?

This means that if I just upload my kohana application, it will break because the RewriteBase in the .htaccess file will be wrong. Is there a way I can have a conditional in the .htaccess file similar to the one I have in the bootstrap so that it will use the correct RewriteBase?

推荐答案

我不认为有一种方法可以有一个条件的RewriteBase 。我想到在Apache中的唯一方法是把的RewriteBase 指令到一个<地点> 标签,但是这是仅在httpd.conf文件本身,而不是在.htaccess文件。

I don't think there is a way to have a conditional RewriteBase. The only way in Apache that comes to mind is putting the RewriteBase directive into a <Location> tag but that is only available in httpd.conf itself, not in .htaccess files.

我通常在这种情况下,什么是定义在当地不同的 AccessFileName 环境,例如 htaccess.txt 。该文件将包含本地重写规则,而的.htaccess 包含服务器端的。

What I usually do in such cases is define a different AccessFileName in the local environment, for example htaccess.txt. That file will contain the local rewrite rules, while .htaccess contains the server side ones.

这篇关于Kohana3:不同的.htaccess的RewriteBase和Kohana的BASE_URL用于开发和生产环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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