简体   繁体   English

在codeigniter中删除index.php

[英]removing index.php in codeigniter

I used the code below to remove index.php in codeigniter in my .htaccess file. 我使用下面的代码删除了.htaccess文件中codeigniter中的index.php。 But the thing that I am confused is where should i use the file. 但是我很困惑的是我应该在哪里使用该文件。 should i use it inside my www folder outside the application or inside the application. 我应该在应用程序外部还是应用程序内部的www文件夹中使用它。

I used it in all places, and it worked but it is messing up with my css or say base folders. 我在所有地方都使用了它,并且它起作用了,但是它弄乱了我的CSS或基本文件夹。 How can I overcome the problem. 我该如何克服这个问题。 Should i use the html base tag? 我应该使用html基本标记吗?

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

EDIT 编辑

my folder structure is 我的文件夹结构是

basefolder
  -application
  -css
  -js
  -images   
  -system
.htaccess
index.php

You can add an RewriteCondition which excludes all exisiting files: 您可以添加一个RewriteCondition,它排除所有现有文件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

use this 用这个

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

if doesn't works check if you enabled mod_rewirte in phpinfo(); 如果不起作用,请检查是否在phpinfo(); enabled mod_rewirte phpinfo();

if it doesn't works yet, try to change the $config['uri_protocol']='AUTO' to one of the listed inside application/config/config.php file on line 40/54: 如果尚不可行,请尝试将$config['uri_protocol']='AUTO'更改为第40/54行上的application/config/config.php文件中列出的内容之一:

|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';

sometimes i used : REQUEST_URI instead of AUTO 有时我用: REQUEST_URI而不是AUTO

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

This assumes css is in the same directory as index.php, etc. This rule depends on your file structure. 这假定css与index.php等在同一目录中。此规则取决于您的文件结构。 If you update your question with an example of your directory tree I can modify the rules. 如果使用目录树示例更新问题,则可以修改规则。

There should be no other configuration needed for this since you mention it works but just messes things up. 因为您提到它可以工作,但是应该搞乱一切,因此不需要其他配置。

It should be noted, this one pasted is the only thing in my CI htaccess file and mine works fine. 应当指出,此粘贴是我的CI htaccess文件中唯一的内容,我的工作正常。

Also, see Will's comment. 另外,请参阅Will的评论。 My config url suffix is always "" 我的配置网址后缀始终为“”

My solution, CI system move up (not public from the web), applications are public, .htaccess for each subdomains (in root directory), but its depends on your structure (many solutions exists) 我的解决方案是CI系统向上移动(不是从Web公开),应用程序是公共的,每个子域都是.htaccess (在根目录中),但是它取决于您的结构(存在许多解决方案)

RewriteBase /
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L] 

copy and paste below code in .htaccess file 将以下代码复制并粘贴到.htaccess文件中

Options +FollowSymLinks 选项+ FollowSymLinks

RewriteEngine On RewriteEngine开

Options -Indexes 选项-索引

RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\\ /index.php\\ HTTP/ RewriteRule ^index.php$ http://www.yoursite.com/ [R=301,L] RewriteCond%{THE_REQUEST} ^ [AZ] {3,9} \\ /index.php \\ HTTP / RewriteRule ^ index.php $ http://www.yoursite.com/ [R = 301,L]

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

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