Remove index.php from Codeigniter URL in Wamp

2019-08-07 19:05发布

问题:

I have big problem trying to remove index.php from url's

i have searched lots if forums (this also), but no help for my situation.

so i have config.php file

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

my .htaccess file in public_html folder near index.php.

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

i have rewrite_module ON (and it's working) and my httpd.conf AllowOverride set to All

so when i am going to mydomain.com/controller/action - I get 404 but when i go to mydomain.com/index.php/controller/action - everything is OK..

i have tried lots of .htaccess examples... and so on.. nothing helps..

回答1:

.htaccess (This should be place outside application folder)

Paste this

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

Note : Sometime index.php will not remove in windows. But if you upload it to server it will work fine. This happen me too in XAMPP but if i upload it to host(Linux) it works fine



回答2:

My Config which is working fine :

config.php

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

.htaccess

# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php

# Rewrite engine
RewriteEngine On

# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]


标签: codeigniter