2015-02-07 2 views
0

У меня возникла проблема с настройкой локальной тестовой среды с использованием codeigniter и уже существующего кода.codeigniter on xampp хочет, чтобы я использовал index.php в uri

Ну, проблема в том, что я не могу открыть страницу, не имея «index.php» в моем URL-адресе. Итак, «test.mydomain.local/index.php/search» отлично работает, а «test.mydomain.local/search» - нет. Но все ссылки в коде, исключая URL-адреса действий в тегах форм, не имеют этого «index.php» в URL-адресе.

Как я могу решить проблему, чтобы 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" в остросюжетном URL в виде тегов. Но на самом деле я не хочу иметь этот index.php в любом URL-адресе. Так что мой 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> 

Может кто-нибудь мне помочь? Это сводит меня с ума!

+0

есть много вопросов и ответить, как этот problem.You может посмотреть документацию https://ellislab.com/codeigniter/user -руководство/общее/urls.html –

ответ

0

Я использую xampp и нашел этот htaccess лучшим. Не пытайтесь поместить свой базовый url в 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'] = ''; 
Смежные вопросы