[英]removing index.php in codeigniter
我使用下面的代码删除了.htaccess文件中codeigniter中的index.php。 但是我很困惑的是我应该在哪里使用该文件。 我应该在应用程序外部还是应用程序内部的www文件夹中使用它。
我在所有地方都使用了它,并且它起作用了,但是它弄乱了我的CSS或基本文件夹。 我该如何克服这个问题。 我应该使用html基本标记吗?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
编辑
我的文件夹结构是
basefolder
-application
-css
-js
-images
-system
.htaccess
index.php
您可以添加一个RewriteCondition,它排除所有现有文件:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
用这个
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
如果不起作用,请检查是否在phpinfo();
enabled mod_rewirte
phpinfo();
如果尚不可行,请尝试将$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';
有时我用: REQUEST_URI
而不是AUTO
RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
这假定css与index.php等在同一目录中。此规则取决于您的文件结构。 如果使用目录树示例更新问题,则可以修改规则。
因为您提到它可以工作,但是应该搞乱一切,因此不需要其他配置。
应当指出,此粘贴是我的CI htaccess文件中唯一的内容,我的工作正常。
另外,请参阅Will的评论。 我的配置网址后缀始终为“”
我的解决方案是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]
将以下代码复制并粘贴到.htaccess文件中
选项+ FollowSymLinks
RewriteEngine开
选项-索引
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.