2010-06-02 4 views
1

Je suis nouveau à CodeIgniter et le routage.problème de routage dans codeigniter

J'ai un contrôleur Login dont index() charge une vue pour entrer un nom d'utilisateur/mot de passe. Dans la vue, le formulaire a action="login/authenticate". Login-> authenticate() détermine si le login est valide ou non. Si elle est valide, redirect('lobby'), sinon redirect('login')

routes.php:

$route['default_controller'] = "login" 

config.php:

$config['base_url'] = "http://localhost/dts/"; 
$config['index_page'] = "index.php"; 

Le problème est que quand je vais à http://localhost/dts/, cliquez sur Connexion, je suis correctement (?) redirigé vers http://localhost/dts/login/authenticate mais le navigateur indique Object not found!. Mais quand je vais à http://localhost/dts/index.php/ (avec slash), il fonctionne correctement (je redirigés vers http://localhost/dts/index.php/login/authenticate, et je suis connecté)

J'ai essayé de supprimer « index.php » en utilisant un .htaccess:

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

et il ne serait plus ouvert même le http://localhost/dts/

Je suis confus .. ce qui se passe?

+0

Même moi je suis confus. :) – User

Répondre

4

La question est la dernière ligne de votre fichier .htaccess.

Étant donné que votre application se trouve dans un sous-répertoire ("dts"), la barre oblique devant "index.php" ne fonctionnera pas. Essayez de le supprimer afin que votre fichier ressemble à ceci:

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

homme qui a fait l'affaire! Merci! – Obay

+0

ça m'a aidé aussi. Merci beaucoup. – Jason

3

Suivez this article on the CodeIgniter wiki pour configurer correctement votre .htaccess comme suit:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    #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> 
+1

+1 pour le lien vers la documentation. – User