简体   繁体   English

CodeIgniter使用.htaccess文件删除index.php

[英]CodeIgniter Removing index.php using .htaccess file

Removing index.php in CodeIgniter using .htaccess file is not working for me. 使用.htaccess文件在CodeIgniter中删除index.php对我不起作用。 I Tried following code eventhough not working. 我尝试了以下代码,尽管无法正常工作。

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

I tried this http://firstcode.info/codeigniter-removing-index-php-from-url/ . 我尝试了这个http://firstcode.info/codeigniter-removing-index-php-from-url/ But not working.But its working in my localhost. 但是不起作用,但是它可以在我的本地主机上工作。 I also edited httpd.config file.But off no use. 我也编辑了httpd.config文件,但是没有用。 Please help me. 请帮我。

STEP 1 第1步

Open the folder “application/config” and open the file “config.php“. 打开文件夹“application/config”然后打开文件“config.php“. find and replace the below code in config.php file. config.php file.找到并替换以下代码config.php file.

find the below code 找到下面的代码

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

replace with the below code

$config['index_page'] = "

STEP 2 第2步

Write below code in .htaccess file 在.htaccess文件中编写以下代码

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
   </IfModule>

STEP 3 步骤3

“application/config/config.php“, then find and replace the below code “application/config/config.php“,然后查找并替换以下代码

find the below code 找到下面的代码

$config['uri_protocol'] = "AUTO"

replace with the below code

$config['uri_protocol'] = "REQUEST_URI" 

Your mentioned code is correct. 您提到的代码是正确的。

You have to modify apache2.conf (/etc/apache2/apache2.conf --- its my servers path) check your path. 您必须修改apache2.conf(/etc/apache2/apache2.conf-它是我的服务器路径),检查您的路径。

Find this culprit "AllowOverride None" and /var/www/ or /var/www/html 找到此罪魁祸首"AllowOverride None"/var/www//var/www/html

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

update to 更新到

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

Dont forget to sudo service apache2 restart 不要忘记sudo service apache2 restart

Try this code 试试这个代码

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php 
</IfModule>

In my config.php file ihave following settings. 在我的config.php文件中,我有以下设置。

$config['index_page']   = "";
$config['uri_protocol'] = "PATH_INFO";

Please try change base url as well in config.php, If using localhost or domainname.com 如果使用localhost或domainname.com,请尝试在config.php中也更改基本URL。

$config['base_url'] = 'http://localhost/'; // localhost

OR 要么

$config['base_url'] = 'http://domainname.com/'; // domainname.com

add in .htacess 添加.htacess

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$

remove "index.php" from $config['index_page'] in config.php (keep blank value) config.php $config['index_page']中删除“ index.php”(保留空白值)

and fix the permission of project folder. 并修复项目文件夹的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM