问题
I have a little project that i developed for a client in codeigniter 2.1.4 and now, he insists to migrate to codeigniter 3 DEV version. I know that's not a good ideea but... My problem is that i can't remove the index.php from the url.
This is my .htaccess file :
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I have removed the index.php from the config.php file
No luck
I reinstalled the LAMP server (i'm on Ubuntu 12.04'), reconfigured
I have other projects on my local server developed on Codeigniter 2.1.4 and Laravel 4 and they work just fine but this one it's killing me.
Thank you!
回答1:
I made this way:
Created the .htaccess in the root folder of the project with the content:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
Then, in the config.php i modified this line.
From:
$config['url_suffix'] = 'index.php';
To:
$config['url_suffix'] = '';
回答2:
Kindly add the below codes to .htaccess file and include it directly to your /codeigniter_project_folder/.htacess
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L]
回答3:
If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Remove the ?
after index.php
回答4:
Add following lines in .htaccess file
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
And also Edit application/config/config.php file. with
$config[‘index_page’] = “”;
$config[‘uri_protocol’] = “AUTO“;
It will Work.
回答5:
Make a
.htacess
file in your project root folder/Your_codeigniter_project_folder/.htacess
and paste this codeRewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
set a base URL in config.php file
$config['base_url'] = 'http://yourhost/CI_project_folder/';
- set URL suffix
$config['url_suffix'] = '.php';
* If not work please check this *
Make sure in your root folder where
.htacess
stay there have not any file which name is same like your controller name. Example: you have ausers.php
controller also you have a file in/Your_codeigniter_project_folder/users.php
If have please remove it/Your_codeigniter_project_folder/users.php
Make sure your server is rewrite mode on( remove # from start of this line)
LoadModule rewrite_module modules/mod_rewrite.so
回答6:
create new .htaccess file on root of your CI project and add your code there. Do not change .htaccess file on application folder. That's work for me
回答7:
Just Download CI version 2.2.0
Copy .htaccess
and htaccess.txt
from root and paste it in your Codeigniter 3 project.
Don't forget to change project name from .htaccess
file.
回答8:
Create an a new htaccess file in your www/project_folder or your htdocs/project_folder
Make sure mod_rewrite is working my using
echo phpinfo()
Simply paste the following code and it should work:
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /project_folder/index.php/$1 [L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule>
Change the project folder to that of your own
回答9:
I have clone the git repository again and made a clean install of the lamp and now it works.
来源:https://stackoverflow.com/questions/20169545/codeigniter-3-remove-index-php-problems