2014-09-30 171 views
2

我知道这里有很多问题和答案,但我很困惑,我无法解决我的问题。请帮忙!CodeIgniter .htaccess删除服务器上的index.php

我可以很容易地通过这个网址访问我的控制器:

http://www.example.com/new/index.php/welcome

,但我无法通过这个网址得到它: http://www.example.com/new/welcome

我配置我的笨网站的子目录“新”和我的服务器上,我的目录结构是:

/ 
    htdocs 
     new 

/(这是空的),htdocs (这里是我的目录名为“新”和新的(这是我的codeIgniter文件的确切文件夹。 我在这里对“/”和“htdocs”感到困惑,我认为这是我无法处理的事情,因为我的域example.com指向htdocs,即如果我把index.php放在htdocs中,例如.com将加载index.php。

在 “新” 目录我的.htaccess文件是:

RewriteEngine On 
#RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) index.php/$1 

在配置/ config.php文件:

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

我试过$config['uri_protocol']为 “自动”, “REQUEST_URI” 和“QUERY_STRING”等。

使用此配置,我可以删除我的本地主机中的index.php,但我无法修复它在服务器上。请帮忙!!提前致谢。

+0

看看这个页面http://www.htaccessredirect.net/ – 2014-09-30 16:00:37

+0

我忘了:$配置[ 'index_page'] = ''; 不要留空格 – 2014-09-30 16:01:18

+0

有没有空白...队友请帮助我.. 我的服务器是fasthosts – 2014-09-30 16:06:20

回答

1

这一项工作

DirectoryIndex index.php 

RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|robots\.txt) 

RewriteRule ^(.*)$ index.php?/$1 [L] 

请务必从appliation删除的index.php /config/config.php

$config['index_page'] = ''; 
1

与此代码尝试在.htaccess:

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteBase/
RewriteCond $1 !^(index\.php|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule> 
+0

抱歉,没有效果。同样的问题。 – 2014-09-30 14:24:25

+0

试一下:RewriteBase/new。我希望这会对你有用。 – 2014-09-30 14:25:58

+0

再次没有影响。不知道如何解决它:\ – 2014-09-30 14:27:28

1

尝试要么改变

$config['uri_protocol'] = 'PATH_INFO';` 

或改变重写规则使用查询字符串,而不是:

RewriteEngine On 
#RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) index.php?$1 

然后将协议设置为查询字符串:

$config['uri_protocol'] = 'QUERY_STRING';` 
+0

没有效果..同样的问题 – 2014-09-30 14:19:45

2

把这个代码.htaccess文件中new目录

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

不要忘记从删除空格:

$config['index_page'] = ' ';

+0

没有效果......同样的问题..在你指定的上述行中没有空格。 – 2014-09-30 14:23:20

+0

引号之间的空格'''' – Prakash 2014-09-30 14:35:36

+0

不,没有空格。它是这样的: $ config ['index_page'] =''; – 2014-09-30 14:36:57

1

如果你说,它的工作在本地主机上,然后这可能是一个服务器问题。通过在您的视图代码中的某个地方编写phpinfo();来检查服务器mod_rewrite是否处于打开状态。如果它没有打开并且您没有权限,请联系您的主管理员。

1

此代码的工作对我来说:

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

而且config.php文件对我来说

$config['index_page'] = ''; 
0

尝试添加 htaccess的index.php文件后,

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