3

I know there's a lot of questions and answers here but I'm really confused and I couldn't fix my problem yet. Please help!

I can easily access my controller via this url:

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

but I can't get it via this URL: http://www.example.com/new/welcome

I'm configuring my CodeIgniter site in a subdirectory "new" and on my server, my directory structure is:

/  
   htdocs
       new

/ (this is empty), htdocs(here is my directory named as "new" and new(this is the exact folder where I've my codeIgniter files. I'm confused here about "/" and "htdocs", I think this is the thing which I'm not able to handle because my domain example.com is pointing to htdocs i.e if I put index.php in htdocs, example.com will load index.php.

my .htaccess file in "new" directory is :

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

in config/config.php:

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

I've tried $config['uri_protocol'] for "Auto", "REQUEST_URI" and "QUERY_STRING" etc.

With this configuration I'm able to remove index.php in my local host but I can't fix it on server. Please help!! Thanks in advance.

Haider Saeed
  • 277
  • 1
  • 6
  • 19

7 Answers7

2

put this code in .htaccess file inside new directory

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

And dont forget to remove whitespace from:

$config['index_page'] = ' ';

LIGHT
  • 5,604
  • 10
  • 35
  • 78
2

this one worked for me

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]

make sure to remove index.php from appliation/config/config.php

$config['index_page'] = '';
user3137046
  • 224
  • 1
  • 3
1

Try with this code in .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>
Hardik Solanki
  • 3,153
  • 1
  • 17
  • 28
1

Try either changing the

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

or changing the rewrite rule to use the query string instead:

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

Then setting the protocol to query string:

$config['uri_protocol'] = 'QUERY_STRING';`
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
1

If you say that it's working on localhost, then it might be a server problem. Check if the server mod_rewrite is on by writing phpinfo(); somewhere in your view code. If it's not on and you don't have permissions, contact your host admin.

John M.
  • 76
  • 1
  • 4
  • 11
1

This code works for me:

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

And the config.php

$config['index_page'] = '';
Bak
  • 262
  • 1
  • 4
  • 11
0

Try adding ? after index.php in htaccess,

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Nilesh Singh
  • 1,750
  • 1
  • 18
  • 30
Rusidi
  • 1
  • 1