Codeigniter can't remove index from url

2019-07-18 11:00发布

问题:

I am Using CentOS,

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|resources)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteBase /var/www/html/site/

</IfModule>

but geting same problem my pages with index.php works fine but when i remove index.php it's not working...

回答1:

I think it will help you as i am using this one.Put this code in your root folder's htaccess file.

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

Please let me know if it is working or not.



回答2:

This can be a few things.

1( remove the index page from your config file (application/config/config.php)

$config['index_page'] = '';

2( Do you have base_url like this:

$config['base_url'] = 'http://yourdomain.com/';

Note the / at the end.

3( try this .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

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

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

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


回答3:

Simple at your config.php file at your config folder search for index url (index_page) and make it empty

$config['index_page'] = '';


回答4:

Try this it works for me ccnd is my files folder.

RewriteEngine on
RewriteCond $1 !^(index\.php|uploads|images|css|js|lib|img|bootstrap|robots\.txt)
RewriteRule ^(.*)$ /ccnd/index.php/$1 [L]


回答5:

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

Important: 1. you must set $config['index_page'] = ''; in config.php file. 2. site_root is folder name like, wamp/www/site_root.