2011-03-13 57 views
1

当我将文件从本地部署到我的服务器时,我陷入了重定向循环。CodeIgniter在服务器上的子文件夹中重定向循环

Firefox has detected that the server is redirecting the request for this address in a way that will never complete. 

该网站是多语言的,我使用.htaccess文件从uri中删除index.php。我试图将网站部署到我的域中的子文件夹(即http://www.mydomain.com/subfolder),理想情况下我想要这样的网址(http://www.mydomain.com/subfolder/en/welcome)

我的.htaccess文件:

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 

我也曾尝试:

RewriteEngine on 
RewriteBase /subfolder/ 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 

我的config.php:

$config['base_url'] = 'http://www.mydomain.com/subfolder/'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'AUTO'; 

我糅tes.php:

$route['default_controller'] = "home"; 
$route['404_override'] = ''; 

$route['^../products/(:num)'] = "products/products_list/index/$1"; 
$route['^../products'] = "products/products_list/index"; 

$route['^../products/detail/(:num)'] = "products/product/index/$1"; 
$route['^../(.+)$'] = "$2"; 

最后MY_Config类国际化:

class MY_Config extends CI_Config { 

function site_url($uri = '') 
{  
    if (is_array($uri)) 
    { 
     $uri = implode('/', $uri); 
    } 

    if (function_exists('get_instance'))   
    { 
     $CI =& get_instance(); 
     $uri = $CI->lang->localized($uri);    
    } 

    return parent::site_url($uri); 
} 

} 

这种设置工作在我的本地环境很好,我通过http://local.subfolder.com访问,我设置了虚拟主机要做到这一点,但是这当我部署到子文件夹中的服务器时,安装程​​序不起作用。

如果有人能指出问题所在,我会很高兴。对于这篇长文章感到抱歉,但希望尽可能多地提供信息。

在此先感谢

回答

1

我想尝试从RewriteBase

RewriteBase /subfolder 

去除拖尾斜杠也修改您的RewriteCond

RewriteEngine On 
RewriteBase /subfolder 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

我注意到,使用前?/$1似乎也有时在CI工作。

非常有用的文档: http://codeigniter.com/wiki/mod_rewrite/

+0

感谢您的回复,但实际上将uri_protocol更改为REQUEST_URI的确做到了这一点。 – Ozay 2011-03-13 10:00:08

0

如果u想使用htaccess的特定文件夹,你刚刚把你的htaccess与该文件夹中。例如,

如果您使用五个虚拟主机,如v1,v2,v3,v4,v5。如果你想在v3中使用你的htaccess,只需将该文件放在该文件夹中即可。

相关问题