xampp上的codeigniter要我在uri中使用index.php

时间:2015-02-07 12:26:27

标签: codeigniter url xampp uri

我在使用codeigniter和现有代码设置本地测试环境时遇到问题。

嗯,问题是,我无法打开一个页面,而没有" index.php"在我的网址中。所以," test.mydomain.local / index.php / search" " test.mydomain.local / search"才不是。但代码中的所有链接(不包括form-tags中的action-URLs)都没有这个" index.php"在网址中。

我如何解决问题,codeigniter或xampp需要这个" index.php"在URL中?我是否需要在代码中更改某些内容或者在.htaccess中更改内容?

这是我的config.php

$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "index.php";
$config['uri_protocol'] = "AUTO"; 

好吧,这段代码强制了" index.php"在表单标记中的action-URL中。但实际上我不希望在任何URL中都有这个index.php。所以我的config.php应该是这样的,我猜:

$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO"; 

这是.htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    ### force www
    RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
    RewriteRule (.*) h t t p : / / w w w . m y d o m a i n . c o m/$1 [R=301,L]

    RewriteCond %{HTTP_HOST} ^domain.local [NC]
    RewriteRule (.*) h t t p : / / t e s t . d o m a i n . l o c a l/$1 [R=301,L]

    ### if the is not a request for an existing file or directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    ### and the URI does not end with a /
    RewriteCond %{REQUEST_URI} !^([^?]*)/($|\?)

    ### redirect and add the slash.
    RewriteRule ^([^?]*) $1/ [L,R=301]

    ### if the is not a request for an existing file or directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # rewrite to index.php passing the URI as a path, QSA will preserve the existing query string
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    </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>

任何人都可以帮助我吗?这让我疯了!

1 个答案:

答案 0 :(得分:0)

我使用xampp并发现这个htaccess是最好的。不要把你的基本网址放在config / config.php中并删除索引。

的.htaccess

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

你的config.php

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| If this is not set then CodeIgniter will try guess the protocol, domain
| and path to your installation. However, you should always configure this
| explicitly and never rely on auto-guessing, especially in production
| environments.
|
*/

$config['base_url'] = 'http://localhost/project name/';

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';