简体   繁体   English

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

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

I have been trying to fix this for days and have tried the following tutorials: 我已经尝试修复此问题几天,并尝试了以下教程:

  • This on stackoverflow 在stackoverflow上

  • This from CI forums 来自CI论坛

And many many others. 还有许多其他。

None have worked. 没有一个工作。

Here is my problem: 这是我的问题:

Whenever I click the site link in WAMP localhost/ci/index.php/HomeController It works fine. 每当我单击WAMP localhost / ci / index.php / HomeController中的站点链接时,它都可以正常工作。

If I omit the “index.php” from the url (localhost/ci/HomeController), however, it shows me the same folder list as on localhost. 但是,如果我从URL(localhost / ci / HomeController)中省略了“ index.php”,它会显示与localhost相同的文件夹列表。

This is my htaccess file in root: 这是我在根目录下的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> 

And in the config file: 并在配置文件中:

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

This still redirected me to WAMP home page. 这仍然将我重定向到WAMP主页。

I also uncommented this (in the httpd.conf file). 我也对此未发表评论(在httpd.conf文件中)。

LoadModule rewrite_module modules/mod_rewrite.so 

Additional information: 附加信息:

in my routes.php file: 在我的routes.php文件中:

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

My abbreviated file structure: (located at C:\\wamp\\www) 我的缩写文件结构:(位于C:\\ wamp \\ www)

  • /ci / CI
    • /application /应用
      • /cache /高速缓存
      • /config /配置
      • /controllers /控制器
      • /core /核心
      • /errors /错误
      • /helpers /佣工
      • /hooks /挂钩
      • /languages /语言
      • /libraries /库
      • /logs /日志
      • /models /楷模
      • /third_party /第三方
      • /views /意见
      • .htaccess 的.htaccess
      • index.html 的index.html
    • /assets /资产
    • /system /系统
    • .htaccess 的.htaccess
    • index.php 的index.php

Any help is appreciated. 任何帮助表示赞赏。 Sorry if there are already answers on this topic. 抱歉,是否已经有关于此主题的答案。 None have worked for my project. 没有人为我的项目工作过。

Edit : 编辑

If I try this htaccess: 如果我尝试这个htaccess:

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

I get: 我得到:

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]

This is the default htaccess I use for my projects to remove the index.php 这是我用于项目的默认htaccess,用于删除index.php

RewriteBase ( /ci/ ) and RewriteRule ( /ci/index.php ) should reference the base directory of your project. RewriteBase/ci/ )和RewriteRule/ci/index.php )应该引用项目的基本目录。 This is to say, is your project hosted at http://www.yoursite.com/ci/ ? 也就是说,您的项目是否托管在http://www.yoursite.com/ci/

Also, if you are hosting your project on WAMP you need to enable htaccess in the config. 另外,如果要在WAMP上托管项目,则需要在配置中启用htaccess。 To do this, click on the WAMP icon and choose Apache->Apache Modules->rewrite_module. 为此,请单击WAMP图标,然后选择Apache-> Apache Modules-> rewrite_module。 Then restart all services. 然后重新启动所有服务。

Good luck! 祝好运!

Try this htaccess: 试试这个htaccess的:

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

Only three steps are require to remove index.php from url in Codeigniter in WAMP environment. 在WAMP环境中,只需三个步骤即可从Codeigniter中的URL删除index.php。

1) Create .htacess file in parallel to application holder and just copy past the following code: 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) Change $config['index_page'] to blank in config.php in application folder as below: 2)将$ config ['index_page']更改为应用程序文件夹中config.php中的空白,如下所示:

$config['index_page'] = '';

3) Enable “rewrite_module” of apache. 3)启用apache的“ rewrite_module”。

Restart your apache and its done. 重新启动您的Apache及其完成。

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

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

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