简体   繁体   English

想要从Codigniter URL中删除Index.php

[英]Want to remove Index.php from Codigniter URL

I want to remove index.php from code igniter URL ,I had created .htaccess file and stored it in application folder parallel to index.php and also remove 我想从代码点火器URL中删除index.php ,我已经创建了.htaccess文件,并将其存储在与index.php平行的应用程序文件夹中,还删除了

$config['index_page'] = '';

from config.php. 来自config.php。

Code in .htaccess file, which is not working : .htaccess文件中的代码不起作用:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L] 

URL of the project is: 该项目的网址是:

localhost/WCPM/index.php

NOTE : Please Don't mark this question as duplicate because I had already tried lots of solution for the same but none of them works for me , so at last I am asking this question here for the solution 注意请不要将此问题标记为重复,因为我已经尝试过很多解决方案,但是没有一个适合我,所以最后我在这里问这个问题的解决方案

In Config.php Change as Follows 在Config.php中,更改如下

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

And Create .htaccess file like 并创建.htaccess文件,例如

RewriteEngine on
RewriteCond $1 !^(index\.php|[WCPM])
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L]

and Save this in Root Folder [WCPM] ie near Application Folder. 并将其保存在根文件夹[WCPM]中,即在“应用程序文件夹”附近。

For More Details Refer the CI Manual @ http://ellislab.com/codeigniter/user-guide/general/urls.html 有关更多详细信息,请参阅CI手册@ http://ellislab.com/codeigniter/user-guide/general/urls.html

Enable mod_rewrite module in apache. 在apache中启用mod_rewrite模块。

If that doesnt work or mod_rewrite is already enabled, try this 如果不起作用或已经启用了mod_rewrite,请尝试此操作

<IfModule mod_rewrite.c>
RewriteEngine On

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

</IfModule>

First of all, change following setting in your config file. 首先,在config文件中更改以下setting

$config['index_page'] = '';

and then, replace .htaccess file located at your project root folder not in the application folder with the following code.. 然后,使用以下代码替换位于项目根文件夹而不是应用程序文件夹中的.htaccess文件。

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|imgs)
RewriteRule ^(.*)$ index.php/$1 [L]  
RewriteRule ^media/imatges/([0-9]+)/([A-Za-z0-9-]+).jpg?$ imgs/$1  [T=image/jpeg,L]
<Files "index.php">
AcceptPathInfo On
</Files>

This is the entire recommended code to put at the start of your .htaccess file 这是放在.htaccess文件开头的完整建议代码。

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

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