繁体   English   中英

CodeIgniter:无法从网址中删除“ index.php”

[英]CodeIgniter: Trouble removing “index.php” from URL

我已经尝试修复此问题几天,并尝试了以下教程:

  • 在stackoverflow上

  • 来自CI论坛

还有许多其他。

没有一个工作。

这是我的问题:

每当我单击WAMP localhost / ci / index.php / HomeController中的站点链接时,它都可以正常工作。

但是,如果我从URL(localhost / ci / HomeController)中省略了“ index.php”,它会显示与localhost相同的文件夹列表。

这是我在根目录下的htaccess文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

并在配置文件中:

$config['base_url'] = 'http://localhost/ci/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; 

这仍然将我重定向到WAMP主页。

我也对此未发表评论(在httpd.conf文件中)。

LoadModule rewrite_module modules/mod_rewrite.so 

附加信息:

在我的routes.php文件中:

$route['default_controller'] = "HomeController";

我的缩写文件结构:(位于C:\\ wamp \\ www)

  • / CI
    • /应用
      • /高速缓存
      • /配置
      • /控制器
      • /核心
      • /错误
      • /佣工
      • /挂钩
      • /语言
      • /库
      • /日志
      • /楷模
      • /第三方
      • /意见
      • 的.htaccess
      • 的index.html
    • /资产
    • /系统
    • 的.htaccess
    • 的index.php

任何帮助表示赞赏。 抱歉,是否已经有关于此主题的答案。 没有人为我的项目工作过。

编辑

如果我尝试这个htaccess:

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

我得到:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
RewriteEngine on
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|js|img|css|captcha|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

这是我用于项目的默认htaccess,用于删除index.php

RewriteBase/ci/ )和RewriteRule/ci/index.php )应该引用项目的基本目录。 也就是说,您的项目是否托管在http://www.yoursite.com/ci/

另外,如果要在WAMP上托管项目,则需要在配置中启用htaccess。 为此,请单击WAMP图标,然后选择Apache-> Apache Modules-> rewrite_module。 然后重新启动所有服务。

祝好运!

试试这个htaccess的:

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

在WAMP环境中,只需三个步骤即可从Codeigniter中的URL删除index.php。

1)与应用程序持有人并行创建.htacess文件,只需复制以下代码即可:

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

2)将$ config ['index_page']更改为应用程序文件夹中config.php中的空白,如下所示:

$config['index_page'] = '';

3)启用apache的“ rewrite_module”。

重新启动您的Apache及其完成。

详细信息: http//goo.gl/3jfW8f

暂无
暂无

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

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