问题
I am trying to remove 'index.php' from the URL. I have tried by making
$config['uri_protocol'] = 'AUTO';
as
$config['uri_protocol'] = 'REQUEST_URI';
and
$config['index_page'] = 'index.php';
as
$config['index_page'] = '';
and even tried with putting
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /project/index.php/$1 [L]
in .htaccess file, but it not working me. Can anyone please tell me where I am going wrong? Thanks in advance..
回答1:
Given that you've told me you're using Ubuntu...
- Use the .htaccess configuration provided by Ayman.
- Open a terminal and type
sudo a2enmod rewrite
to enablemod_rewrite
on your machine. - Open 000-default with
sudo nano /etc/apache2/sites-enabled/000-default
and change the first occurence ofAllowOverride None
toAllowOverride All
Then restart apache with sudo service apache2 restart
.
Also use: $config['index_page'] = '';
回答2:
There are 3 steps to remove index.php
1.Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.Make .htacces file in your root directory using below code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
3.Enable rewrite mode
i. First, initiate it with the following command:
a2enmod rewrite
ii. Edit the file /etc/apache2/sites-enabled/000-default
change the AllowOverride None to AllowOverride All.
iii. Restart your server with the following command:
sudo /etc/init.d/apache2 restart
回答3:
Got the answer, I just had inserted the following code in my .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and made
$config['index_page'] = '';
in config.php
source: Remove "index.php" from URL - Codeigniterr
Answered by: @Akhilraj N S
回答4:
This is the .htaccess
file I always use. Works for me:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /project/
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
来源:https://stackoverflow.com/questions/14848325/trying-to-remove-index-php-from-url-in-codeigniter