Trying to remove index.php from URL in codeigniter [duplicate]

我只是一个虾纸丫 提交于 2019-12-24 14:33:13

问题


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...

  1. Use the .htaccess configuration provided by Ayman.
  2. Open a terminal and type sudo a2enmod rewrite to enable mod_rewrite on your machine.
  3. Open 000-default with sudo nano /etc/apache2/sites-enabled/000-default and change the first occurence of AllowOverride None to AllowOverride 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 - Codeigniter‌​r

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!