2009-07-16 13 views
0

J'expérimente avec cadre CodeIgniter PHP, ce cadre fonctionne comme:Réécrire Url avec apache2

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

Alors, j'ai essayé d'enlever index.php partie de là. Jusqu'à présent, je fais ces:

  1. faire $config['index_page'] = "index.php"; à $config['index_page'] = "";

  2. font $config['uri_protocol'] = "REQUEST_URI"; de $config['uri_protocol'] = "AUTO";

  3. permettent mod_rewrite apache par "a2enmod rewrite"

  4. mettre un fichier .htaccess à /ci Répertoire:

    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. Et bien sûr redémarrer le serveur apache

Voici mes journaux apache avec ces configurations:

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] 

Voici le résultat dans Firefox:

404 pas trouvé:
L'URL /index.php demandée n'a pas été trouvée sur ce serveur.


Alors, que dois-je faire (ou si je me trompe) pour trouver du travail ces URL? http://localhost:7777/~dhalsim/ci/blog/ au lieu de http://localhost:7777/~dhalsim/ci/index.php/blog/

Répondre

0

Voici comment je le résoudre:

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

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

Puis dans le fichier 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'] = ""; 

MISE À JOUR

Dans le fichier 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

n'a pas fonctionné pour moi, désolé – dhalsim

+0

$ config ['base_url'] \t = "http: // localhost: 7777/~ dhalsim/ci /"; // est-ce que c'est réglé? –

0

Utilisez la règle suivante:

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] 

Pour que cela fonctionne, vous devez configurer votre application CodeIgniter sur un autre port ou utilisation/etc/hosts pour donner simple Vhost (127.0.0.1 ci et http://ci:7777/ avec Apache configuré pour utiliser le ci vhost.). Ensuite, vous pouvez définir l'URL de base à / et ne pas s'inquiéter à ce sujet. Sinon, vous devrez faire face à des problèmes de répertoire confus et mod_rewrite.