2009-07-16 2 views
0

Я экспериментировал с CodeIgniter PHP рамки, эта система работает так:Перепишите Url с apache2

http://localhost:7777/~dhalsim/ci/index.php/blog

Итак, я попытался удалить index.php часть оттуда. До сих пор я этим:

  1. сделать $config['index_page'] = "index.php"; в $config['index_page'] = "";

  2. сделать $config['uri_protocol'] = "REQUEST_URI"; из $config['uri_protocol'] = "AUTO";

  3. позволяют апачский mod_rewrite на "a2enmod rewrite"

  4. поместить файл .htaccess в /ci справочник:

    RewriteEngine on 
    RewriteBase/
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php/$1 [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
    
  5. И конечно перезапустить сервер Apache

Вот мои Apache журналы с этими конфигурациями:

127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] strip per-dir prefix: /home/dhalsim/public_html/ci/blog -> blog 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] applying pattern '^(.*)$' to uri 'blog' 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) [perdir /home/dhalsim/public_html/ci/] RewriteCond: input='/~dhalsim/ci/blog' pattern='^system.*' => not-matched 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] strip per-dir prefix: /home/dhalsim/public_html/ci/blog -> blog 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] applying pattern '^(.*)$' to uri 'blog' 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) [perdir /home/dhalsim/public_html/ci/] RewriteCond: input='/home/dhalsim/public_html/ci/blog' pattern='!-f' => matched 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) [perdir /home/dhalsim/public_html/ci/] RewriteCond: input='/home/dhalsim/public_html/ci/blog' pattern='!-d' => matched 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (2) [perdir /home/dhalsim/public_html/ci/] rewrite 'blog' -> 'index.php?/blog' 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) split uri=index.php?/blog -> uri=index.php, args=/blog 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] add per-dir prefix: index.php -> /home/dhalsim/public_html/ci/index.php 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (2) [perdir /home/dhalsim/public_html/ci/] trying to replace prefix /home/dhalsim/public_html/ci/ with/
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (5) strip matching prefix: /home/dhalsim/public_html/ci/index.php -> index.php 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) add subst prefix: index.php -> /index.php 
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (1) [perdir /home/dhalsim/public_html/ci/] internal redirect with /index.php [INTERNAL REDIRECT] 

Вот результат в Firefox:

404 Не найдено:
Запрашиваемый URL /index.php не был найден на этом сервере.


Итак, что я должен делать (или там, где я не прав), чтобы получить работу этих URL-адресов? http://localhost:7777/~dhalsim/ci/blog/ вместо http://localhost:7777/~dhalsim/ci/index.php/blog/

ответ

0

Вот как я решить ее:

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|flash|css|js|robots\.txt|downloads) 

RewriteRule ^(.*)$ /index.php/$1 [L] 

Затем в файле config.php

/* 
|-------------------------------------------------------------------------- 
| Base Site URL 
|-------------------------------------------------------------------------- 
| 
| URL to your CodeIgniter root. Typically this will be your base URL, 
| WITH a trailing slash: 
| 
| http://example.com/ 
| 
*/ 
$config['base_url'] = "http://localhost:7777/~dhalsim/ci/"; 

/* 
|-------------------------------------------------------------------------- 
| 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'] = ""; 

UPDATE

В routes.php файле :

//Point to default controller 
$route['default_controller'] = "site/home"; //Set to your controller 

// Point to the right controller 
$routing_array = array(
      'blog' => 'site/blog', 
     ); // set to your blog controler 
+0

$ config ['uri_protocol'] \t = "AUTO"; –

+0

не работал для меня, извините – dhalsim

+0

$ config ['base_url'] \t = "http: // localhost: 7777/~ dhalsim/ci /"; // это набор? –

0

Используйте следующее правило перезаписи:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^(.*)$ /index.php/$1 [NC,L] 

Для того, чтобы это работало вы должны настроить ваш CodeIgniter приложение на другой порт или с помощью кнопок/и т.д./хостов, чтобы дать ему простой ВХост (127.0.0.1 ci и http://ci:7777/ с Apache, чтобы использовать ci vhost.). Затем вы можете установить базовый url на / и не беспокоиться об этом. В противном случае вам придется иметь дело с запутанными проблемами с каталогом и mod_rewrite.

Смежные вопросы