0

I want to remove index.php to access my controllers directly. However, I cannot directly go my controller. I have to use index.php. For example: I want to go http://example.com/my_controller/method instead of http://example.com/index.php/my_controller/method

By the way, I used my test server, not local server like XAMPP. I enabled apache mod rewrite in my server.

I tried a lot of htaccess rules, conditions but I cannot work it. Please help me!

This is my .htaccess file:

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

my config.php:

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

How can I go directly?

bekirsevki
  • 302
  • 7
  • 20
  • 4
    Possible duplicate of [CodeIgniter removing index.php from url](http://stackoverflow.com/questions/19183311/codeigniter-removing-index-php-from-url) – random_user_name Jan 15 '16 at 22:20
  • First of what version of codeigniter are you using and what localhost xampp, wamp etc –  Jan 15 '16 at 22:29
  • I use my server to test it. – bekirsevki Jan 15 '16 at 22:46
  • If your using wamp make sure you have enabled apache mod rewrite. And make your your htaccess is in main directory out side of application folder. –  Jan 15 '16 at 22:50
  • @wolfgang1983 No, I dont use it since I use my test server, not a local server. Also, I enabled apache mod rewrite in my server and I tried main directory. – bekirsevki Jan 15 '16 at 22:51
  • @cale_b I tried all of answers but It cannot work :( – bekirsevki Jan 15 '16 at 22:55

2 Answers2

1

How about verifying that mod_rewrite is actually enabled. You could follow the instructions here: How to check whether mod_rewrite is enable on server?

Community
  • 1
  • 1
plhyhc
  • 121
  • 1
  • 6
  • Yes, I checked and it is enabled. The image link is http://pasteboard.co/P513xT9.png – bekirsevki Jan 15 '16 at 23:44
  • How about removing the If statement... – plhyhc Jan 15 '16 at 23:52
  • How about testing rewrite by following these instructions to intentionally to get HTTP 500 error. That should prove it is working. http://stackoverflow.com/questions/9234289/verify-if-htaccess-file-is-running – plhyhc Jan 17 '16 at 02:57
0

Try this code in your .htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
sasy
  • 493
  • 3
  • 9
  • 21