7

ok, i did exactly as asked in the documentation of codeigniter, created new file .htaccess

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

i am using xampp, so my url for accessing the site was

http://localhost:12/projects/zorkif_nextgen/index.php/main

now after applying the above .htaccess file, i tried it without index.php like this

http://localhost:12/projects/zorkif_nextgen/main

but instead of working, it is redirecting me to this url

http://localhost:12/xampp

How to resolve this issue?

plus i am getting error on my page after trying the .htaccess

on top of page message is appearing,

 Error Occured.
Warning!. Make sure you perform the correct action.
The Action has been completed Successfully. 

Edit:

Here is some of my config.php file settings

$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['enable_hooks'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger']   = 'c';
$config['function_trigger']     = 'm';
$config['directory_trigger']    = 'd'; // experimental not currently in use
$config['sess_cookie_name']     = 'zk_ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'sys_ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['rewrite_short_tags'] = FALSE;
PeeHaa
  • 66,697
  • 53
  • 182
  • 254
Sizzling Code
  • 5,223
  • 16
  • 68
  • 124
  • Exact and complete answer http://stackoverflow.com/questions/14297770/cannot-remove-index-php-from-codeigniter-url – Sami Sep 22 '13 at 07:49
  • Instead of `RewriteRule ^(.*)$ /index.php/$1 [L]` use `RewriteRule ^(.*)$ index.php/$1 [L]` in your root folder/.htaccess – RN Kushwaha Jan 25 '15 at 17:54

7 Answers7

15

this is works well for me:

1- create .htaccess file in the root folder with the following content

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

2- from the config file change $config['index_page'] = 'index.php'; to $config['index_page'] = '';

Mohamed Nagy
  • 1,053
  • 1
  • 11
  • 31
7

Try defining the RewriteBase to /projects/zorkif_nextgen

RewriteBase /projects/zorkif_nextgen
DaneoShiga
  • 967
  • 7
  • 16
2

Try the following

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
AkisC
  • 749
  • 2
  • 9
  • 24
  • Thankyou for reply, i tried your code, It works but it is same, i have to write the index.php to make it work. if i try zorkif_nextgen/main then it again redirects me to the localhost:12/xampp?? why its redirecting me to the main root.? – Sizzling Code Mar 11 '13 at 23:10
  • I've tried 10 of these. you're is the one that worked for my xampp. – usumoio Feb 09 '14 at 02:48
2
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
1

You can try this

<IfModule mod_rewrite.c> 
   RewriteEngine on 
   RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt) 
   RewriteRule ^(.*)$ /ci/index.php/$1 [L] 
</IfModule>

For future reading This will help you Codeigniter remove index php from url using htaccess

goenk
  • 31
  • 5
1

You may have look at config/routes.php.

It may have been set to a default controller.

-1

Don't use an .htaccess file to remove index.php from your URLs. This is an issue in your config. Look specifically at $config['base_url'] and $config['index_page']

landons
  • 9,374
  • 3
  • 31
  • 46