2015-01-12 144 views
0

我试图从url中删除index.php过去4天,但没有成功。在codeigniter中删除index.php -htaccess

http://domainName.com/CI/index.php/controller-name/function/parameter

CI是GoDaddy的托管文件夹。

/
的.htaccess
CI

谷歌搜索后,我试着用下面的代码,但只得到一个空白页或错误:500,也是我不明白的逻辑。请有人帮我找到我出错的地方。

RewriteEngine on 
RewriteCond $1 !^(index\.php|[Javascript/CSS/Image root Folder name(s)]|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

第二

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

我也改了行,CI /应用/配置/ config.php文件

$config['index_page'] = '';

$config['uri_protocol'] = “REQUEST_URI”

+0

试试这个: HTTP://计算器.com/questions/14783666/codeigniter-htaccess-and-url-rewrite-issues/14807463#14807463 –

+0

如何在godaddy服务器中允许override(apache.conf)..在我的服务器中什么都不起作用。我的base_url是http://domain.com/ci/ –

回答

0

这应该工作

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

在你的例子中,你没有使用RewriteBase将它设置为CI文件夹,因为在你的应用程序所在的文件夹中。这是一个动态设置RewriteBase的例子。它可能是有用的。 http://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically –

+0

即使添加RewriteBase/CI ..它不起作用,任何其他解决方案。 –

0

刚试试这个工作指回复我

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

只是将其保存在您的HTT文件中并尝试 – Prasanna

+0

感谢您的答案,但它不起作用。没有指定输入文件。 –

0

按照以下的步骤:

  1. 更改配置文件是这样的:

    $配置[ 'index_page'] = '';

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

  2. 使用下面的.htaccess:

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

注:的.htaccess取决于服务器。有些服务器(例如:Godaddy的)需要使用下面的.htaccess:

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

see here

使用在BASE_URL下面的代码:

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/'); 
+0

在apache.conf中更改允许ovveride后,它在localhost中工作正常。即使在godaddy服务器中没有解决问题,它也会显示“没有指定输入文件。”。将您的htaccess代码放到URL domainName.com/CI/index时。 php/controller-name/function /参数更改为domainName.com /?/ controller-name/function/parameter ...任何帮助。 –

+0

您需要为godaddy使用最后的.htaccess。这是一个特例。 –

+0

我是否需要在上面提到的htaccess代码中输入文件夹名称ci –