Coldfire
Coldfire

Reputation: 177

remove index.php from the url in Codeigniter on host server

Hi all im trying to hide the index.php from the url, well something like that:

i want : mydomain.com/index.php/mycontroler

to be like : mydomain.com/mycontroler

here is my .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] 

And here is my conf.php

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

the problem is that it was working good in the local but not in the server

here is the disposition of my files

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

Help guys

Upvotes: 0

Views: 2818

Answers (4)

Filippo oretti
Filippo oretti

Reputation: 49813

$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]

if still getting troubles try changing :

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

or somenthing different more (in the config.php you'll find all the options available to try for the uri_protocol param)

Upvotes: 3

Dash
Dash

Reputation: 314

Make the below changes in the root .htaccess file

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

It worked for me.

Upvotes: 0

Fu Xu
Fu Xu

Reputation: 766

all my .htaccess

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

and you should make sure that property AllowOverride is set correct, eg:AllowOverride ALL in your httpd.conf Directory segment

Upvotes: 0

Manish Chauhan
Manish Chauhan

Reputation: 570

Here is .htaccess stuff,

<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 *

And in config.php

  1. Set base URL like 'http://www.example.com/'
  2. Set $config[‘index_page’] to an empty
  3. string Set $config['uri_protocol'] = 'REQUEST_URI'

Upvotes: 0

Related Questions