2013-07-16 98 views
7

我在本地使用Codeigniter WAMP。这里的代码工作正常。但我上传在Cpanel(在example.com中,文件夹名称调用'mysite')。还有我改变,CodeIgniter只显示默认控制器

  • DB_NAME(CONFIG/database.php中)
  • db_user_name(CONFIG/database.php中)
  • DB_PASSWORD(CONFIG/database.php中)
  • BASE_URL如http://example.com/mysite(CONFIG /的config.php)
  • uri_protocol如REQUEST_URI(CONFIG/config.php中)

也改变.htaccess(mysite的/ htaccess的)为,

<IfModule mod_rewrite.c> 

RewriteEngine On 

# Set the rewritebase to your CI installation folder 
RewriteBase /mysite/ 


# Send everything to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

但不在mysite/application/.htaccess中。它是空的。

问题是,如果我去http://example.com/mysite,它显示默认页面正确。但是,如果我点击任何链接(http://example.com/mysite/user/signin),它会显示相同的默认页面。但URL已更改。

帮帮我吧,求你了......

的config.php

$config['base_url'] = 'http://example.com/mysite'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 
$config['url_suffix'] = ''; 
$config['language'] = 'english'; 
$config['charset'] = 'UTF-8'; 
$config['enable_hooks'] = FALSE; 
$config['subclass_prefix'] = 'MY_'; 
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; 
$config['allow_get_array']  = TRUE; 
$config['enable_query_strings'] = FALSE; 
$config['controller_trigger'] = 'c'; 
$config['function_trigger']  = 'm'; 
$config['directory_trigger'] = 'd'; 
$config['log_threshold'] = 0; 
$config['log_path'] = ''; 
$config['log_date_format'] = 'Y-m-d H:i:s'; 
$config['cache_path'] = ''; 
$config['encryption_key'] = '***'; 
$config['sess_cookie_name']  = 'ci_session'; 
$config['sess_expiration']  = 7200; 
$config['sess_expire_on_close'] = FALSE; 
$config['sess_encrypt_cookie'] = FALSE; 
$config['sess_use_database'] = FALSE; 
$config['sess_table_name']  = 'ci_sessions'; 
$config['sess_match_ip']  = FALSE; 
$config['sess_match_useragent'] = TRUE; 
$config['sess_time_to_update'] = 300; 
$config['cookie_prefix'] = ""; 
$config['cookie_domain'] = ""; 
$config['cookie_path']  = "/"; 
$config['cookie_secure'] = FALSE; 
$config['global_xss_filtering'] = FALSE; 
$config['csrf_protection'] = FALSE; 
$config['csrf_token_name'] = 'csrf_test_name'; 
$config['csrf_cookie_name'] = 'csrf_cookie_name'; 
$config['csrf_expire'] = 7200; 
$config['compress_output'] = FALSE; 
$config['time_reference'] = 'local'; 
$config['rewrite_short_tags'] = FALSE; 
$config['proxy_ips'] = ''; 
define('CSS_FOLDER' , 'application/assets/css'); 
define('DEFAULT_IMAGE_URL' , 'application/assets/images/default'); 

routes.php文件

$route['default_controller'] = "welcome"; 
$route['404_override'] = ''; 
$route['user/(:any)'] = 'user/index'; 
+0

,你能否告诉我们'配置/ config.php'和'配置/ routes.php'? – Boris

+0

@bborisovs现在你可以看到... – KarSho

+0

你的应用程序位于子文件夹中? – bottleboot

回答

6
$config['base_url'] = 'http://example.com/mysite/'; 

比 “AUTO” :

$config['base_url'] = 'http://example.com/mysite'; 

试试这个:

RewriteBase/

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

这看起来像对我来说是正确的答案 – bottleboot

1

如果您打算在服务器上使用的子文件夹中做同样的在当地的WAMP。通过这种方式,您可以在将其发送到服务器之前进行测试。

我很久以前使用CI,但我认为你必须在某些配置文件中添加mysite/

参见:Installing a CodeIgniter application in a subfolder

+0

看到我的文件有问题 – KarSho

+1

把你的页面放在'WAMP'的mysite /'文件夹中。如果它会工作的问题不在CI中。 – furas

+0

我在本地WAMP中将我的文件夹名称更改为mysite1,并尝试使用http:// localhost/mysite1 /。它工作正常。我只改变了$ config ['base_url'] \t ='http:// localhost/mysite1 /'; – KarSho

1

的.htaccess代码

恢复默认的配置,以config.php文件,希望这有助于你。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 
1

有时“ORIG_PATH_INFO”解决了这个问题。所以,你也可以改变uri_protocol再次尝试“ORIG_PATH_INFO”

$config['uri_protocol'] = "ORIG_PATH_INFO"; 

和 的BASE_URL应该是绝对的,

$config['base_url'] = "http://example.com/mysite/"; 
1

笨可以告诉加载默认控制器当URI不存在,就像只有你的网站根URL被请求的情况一样。所以一旦你的默认控制器'welcome'替换为你的控制器在路由中。PHP的,它可以帮助你

1
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
1

试试这个htaccess的:

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

你也应该创建一个名为控制器的用户和这个控制器应该ahve功能登入。

1

我使用下面的.htaccess文件,它适用于我与cpanel。

# index file can be index.php, home.php, default.php etc. 
DirectoryIndex index.php 

# Rewrite engine 
RewriteEngine On 

# condition with escaping special chars 
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA] 
1

在routes.php文件文件中删除

$route['user/(:any)'] = 'user/index'; 

。用户/登录符合上述条件,这就是为什么CI将请求路由到用户/索引而不是您的“用户”控制器“登录”功能。

你想通过该路由配置实现什么?

1

打开config.php文件,并做以下内容替换

$config['index_page'] = "index.php" 
to 
$config['index_page'] = "" 

在某些情况下,uri_protocol默认设置无法正常工作。 只需更换 $配置[ 'uri_protocol'] =通过 $配置[ 'uri_protocol'] = “REQUEST_URI”

的.htaccess

RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
3

当我使用自动和PATH_INFO为同一

在config.php ..try使用

$config['uri_protocol'] = 'AUTO'; 

确保rewrite_module我面临解决同一个问题..its是在阿帕奇

0

还有,你必须考虑几件事情。当你用codigniter框架设置你的项目。以下是您必须进行更改的文件。

1)的.htaccess:

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

2)应用程序/配置/配置。PHP

$config['base_url'] = 'http://example.com/mysite/'; 
$config['server_root'] = $_SERVER['DOCUMENT_ROOT']; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'AUTO'; 

3)的application/config/database.php中

$db['default']['hostname'] = 'localhost'; // set your hostname 
$db['default']['username'] = 'root'; // set database username 
$db['default']['password'] = 'root'; //set database password 
$db['default']['database'] = 'XYZ'; //set your database name 
$db['default']['dbdriver'] = 'mysql'; 

4)的application/config/routes.php文件

$route['default_controller'] = "user"; //your default controller 
$route['404_override'] = ''; 

注:.htaccess文件必须位于根目录中。在这里它应该在mysite文件夹

1

我解决了同样的问题,通过更改控制器文件名以大写字母开头。

就像下载的默认“欢迎”控制器一样。

+0

对我来说,它是和模型。视图是小写的。 MAMP不关心案件。 – osxconor

0

试试这个

$config['uri_protocol'] = 'PATH_INFO'; 
$config['enable_query_strings'] = FALSE; 

Httaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 

#Checks to see if the user is attempting to access a valid file, 
#such as an image or css document, if this isn't true it sends the 
#request to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [NC] 
</IfModule>