且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何清除index.php在ubuntu服务器上的codeigniter?

更新时间:2023-02-21 21:57:37

我面临着同样的问题,但能够纠正它。我给你完整的指示。



通过键入以下命令,首先检查mod_rewrite是否打开或不是来自Terminal:

  sudo a2enmod rewrite 

然后打开文件 apache2.conf ,位于下面提到的目录中

  / etc / apache2 / apache2 .conf 

查找< Directory / var / www / code>并更改 AllowOverride None AllowOverride All



如果不允许您保存文件,则意味着目录没有所需的权限。所以请通过运行下面的命令。



sudo chmod -R 777 / etc / apache2 / 保存文件。



现在写入 .htaccess 文件并通过放置以下代码保存文件。 p>

RewriteEngine on
RewriteCond $ 1!^(index\.php | resources | robots\.txt)
RewriteCond% {REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^(。*)$ index.php / $ 1 [QSA,L]



然后通过以下命令重新启动apache服务

  sudo服务apache2 restart $希望这将有效...  

I have researched on all the question on *** to remove index.php from codeigniter but still i am unable to do it. Only landing page opens but rest of the pages are blank. I m using own ubuntu linux server. My rewrite module is also on. I tried $config['uri_protocol'] with all possible values. AUTO, PATH_INFO, QUERY_STRING, ORIG_PATH_INFO. My htaccess code is here

RewriteEngine on
AddType text/x-component .htc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

vhost file is here

DocumentRoot /home/black-sheep/black-sheep.org

    <Directory />
            Options FollowSymLinks
            AllowOverride FileInfo
    </Directory>

    <Directory /home/black-sheep/black-sheep.org/>
            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 /var/log/apache2/error.log

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

    CustomLog /var/log/apache2/access.log combined

My website url is

http://black-sheep.org/

This is the path when i echo __FILE__ on index.php

/home/black-sheep/black-sheep.org/index.php

Its amazing that wordpress site on same server without index.php is running good with following htaccess.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

I tried with this htaccess also but it doesn't work for me.

Please suggest me the solution. Thanks in advance

I was facing the same problem but able to correct it. I am giving you the full instruction. follow step by step..

First check whether mod_rewrite is on or not from Terminal by typing the below command :

sudo a2enmod rewrite

Then open file apache2.conf which is located in the below mentioned directory

/etc/apache2/apache2.conf

Find <Directory /var/www/> in the file and change AllowOverride None to AllowOverride All

If it is not allowing you to save the file, that means the directory don't have the required permission. so please give that by running the below command.

sudo chmod -R 777 /etc/apache2/ and then save the file.

Now write your .htaccess file and save the file by placing the below codes.

RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Then restart your apache service once by the below command

sudo service apache2 restart

Hopefully, then it will work...