如何从 UBUNTU 中的 codeigniter 中删除 index.php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16556915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:21:41  来源:igfitidea点击:

How to remove index.php from codeigniter in UBUNTU

php.htaccesscodeignitermod-rewrite

提问by Suresh Kamrushi

I know this question is being ask already, i tried all those but still unable to remove index.php from url. Here are my details

我知道这个问题已经有人问过了,我尝试了所有这些,但仍然无法从 url 中删除 index.php。这是我的详细信息

Ubuntu 12.10
PHP : 5.4.6
Mod_rewrite in on
CI verson: 2.1

.htacess look like:

.htacess 看起来像:

RewriteEngine On
RewriteBase /projectname

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]  

I also look at the below link but no luck.. Cannot remove index.php from url CI based site

我也看看下面的链接,但没有运气.. 无法从基于 url CI 的站点中删除 index.php

How to remove "index.php" in codeigniter's path

如何删除codeigniter路径中的“index.php”

My "/etc/apache2/sites-available/default" is look like this:

我的“/etc/apache2/sites-available/default”是这样的:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None 
        </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Any help appreciated!!

任何帮助表示赞赏!

采纳答案by Kinjal Dixit

In application/config/config.phpchange:

application/config/config.php变化:

$config['index_page'] = 'index.php';

to:

到:

$config['index_page'] = '';

it is a good idea to do apache reload everytime you change an apache config file.

每次更改 apache 配置文件时都重新加载 apache 是个好主意。

sudo /etc/init.d/apache2 reload

or:

或者:

sudo service apache2 reload

or:

或者:

sudo /etc/init.d/httpd reload

(or whatever is the equivalent command for your platform)

(或任何适用于您平台的等效命令)

for what it is worth, here is my .htaccess

对于它的价值,这是我的 .htaccess

RewriteEngine on
RewriteBase /
RewriteCond  !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html)
RewriteRule ^(.*)$ index.php/ [L]

回答by Dino

Step 1 :

第1步 :

Add this in htaccess file

将此添加到 htaccess 文件中

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

Step 2 :

第2步 :

Remove index.php in codeigniter config

删除 codeigniter 配置中的 index.php

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

Step 3 :

第 3 步:

Allow overriding htaccess in Apache Configuration (Command)

允许在 Apache 配置(命令)中覆盖 htaccess

sudo nano /etc/apache2/apache2.conf

and edit the file & change to

并编辑文件并更改为

AllowOverride All

for www folder

对于 www 文件夹

Step 4 :

第四步 :

Enabled apache mod rewrite (Command)

启用 apache mod 重写(命令)

sudo a2enmod rewrite

Step 5 :

第 5 步:

Restart Apache (Command)

重启 Apache(命令)

sudo /etc/init.d/apache2 restart

回答by blu

my .htaccess

我的.htaccess

RewriteEngine on

RewriteCond  !^(index.php)

RewriteRule ^(.*)$ index.php/ [L]