Svi*_*ish 11 php .htaccess kohana kohana-3
在我,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;
}
Run Code Online (Sandbox Code Playgroud)
在.htaccess
有这样的:
# Installation directory
RewriteBase /kohana/
Run Code Online (Sandbox Code Playgroud)
这意味着如果我只是上传我的kohana应用程序,它将会中断,因为.htaccess
文件中的RewriteBase 是错误的.有没有办法我可以在.htaccess
文件中有条件类似于我在引导程序中的条件,以便它将使用正确的RewriteBase?
我不认为有条件的方法RewriteBase
.想到Apache的唯一方法就是将RewriteBase
指令放入<Location>
标签中,但只能在httpd.conf本身中使用,而不能在.htaccess文件中使用.
例如,我在这种情况下通常做的是在本地环境中定义不同的AccessFileNamehtaccess.txt
.该文件将包含本地重写规则,同时.htaccess
包含服务器端规则.
我在寻找类似的解决方案时遇到了这个问题.虽然我没有有条件地设置RewriteBase,但我确实通过设置环境变量并在以下规则中使用它来获得类似的效果.这是我的意思的一个例子.
# Set an environment variable based on the server name
RewriteRule %{SERVER_NAME} localhost [E=REWRITEBASE:/local_dir/]
RewriteRule %{SERVER_NAME} prodhost [E=REWRITEBASE:/prod_dir/]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{ENV:REWRITEBASE}%{REQUEST_FILENAME} !-f
RewriteCond %{ENV:REWRITEBASE}%{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^static
# Rewrite all other URLs to index.php/URL
RewriteRule .* %{ENV:REWRITEBASE}index.php/$0 [PT]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5047 次 |
最近记录: |