从主机服务器上的Codeigniter中的url中删除index.php

时间:2013-08-14 04:03:46

标签: php codeigniter

大家好我试图隐藏url中的index.php,就像那样:

我想:mydomain.com/index.php/mycontroler

如:mydomain.com/mycontroler

这是我的.htaccess

Options -Multiviews
Options +FollowSymLinks

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|images|robots\.txt|css)

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

这是我的conf.php

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

问题是它在本地运行良好但不在服务器

这是我的文件的配置

- bin
- etc
- mail
- public_ftp
- public_html
 -- application
 -- assets
 -- system
 -- .htaccess
 -- index.php

帮助人

4 个答案:

答案 0 :(得分:2)

$config['base_url']    = 'http://'.$_SERVER['HTTP_HOST'].'/';
 $config['index_page'] = '';

htaccess的:

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

如果仍然遇到麻烦尝试改变:

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

或somenthing不同更多(在config.php中你会找到所有可用于uri_protocol参数的选项)

答案 1 :(得分:0)

这是.htaccess的东西,

<IfModule mod_rewrite.c>

    Options +FollowSymLinks -Indexes
    RewriteEngine on

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    #AllowOverride All
    #RewriteBase /

    # Restrict your site to only one domain
    #RewriteCond %{HTTP_HOST} !^www\.
    #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    <IfModule mod_php5.c>
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    <IfModule !mod_php5.c>
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>

</IfModule>

#prevent access to htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

#disable directory browsing
Options All -Indexes
IndexIgnore *

在config.php中

  1. 设置基本网址,例如“http://www.example.com/
  2. 将$ config ['index_page']设置为空
  3. string Set $ config ['uri_protocol'] ='REQUEST_URI'

答案 2 :(得分:0)

我所有的.htaccess

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

并且您应该确保属性AllowOverride设置正确,例如:AllowOverride ALL目录段中的httpd.conf

答案 3 :(得分:0)

在根.htaccess文件中进行以下更改

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

它对我有用。