2013-08-20 5 views
1

Bonjour les gars j'ai un problème avec ZF2 avec htaccess. Je crée VHOST et tout fonctionne bien. quand j'appelleZend Framework 2 Htaccess

my-vhost.localhost travailler tout bon, mais quand j'ajouter un segment uri comme index.php ou/1234 Je reçois 404.

Je .htaccess modifier en dir publique et mettre

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^.*$ index.php [NC,L] 

Bur encore j'ai 404. Une idée comment je peux je ralentir cela?

Mon plein .htaccess est:

RewriteEngine On 

# The following rule tells Apache that if the requested filename 
# exists, simply serve it. 

RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 

# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do 
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work 
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution. 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^.*$ index.php [NC,L] 
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
RewriteRule ^(.*) - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

VHOST

<VirtualHost *:80> 
    ServerName zf2-tutorial.localhost 
    DocumentRoot /var/www/html/zf2-tutorial/public 
    SetEnv APPLICATION_ENV "development" 
    <Directory /var/www/html/zf2-tutorial/public> 
     DirectoryIndex index.php 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 

Qui pense problème est routage vérifier mon mod d'itinéraire.

<?php 
return array(
    'controllers' => array(
     'invokables' => array(
      'Album\Controller\Album' => 'Album\Controller\AlbumController', 
     ), 
    ), 

    // The following section is new and should be added to your file 
    'router' => array(
     'routes' => array(
      'album' => array(
       'type' => 'segment', 
       'options' => array(
        'route' => '/album[/][:action][/:id]', 
        'constraints' => array(
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'id'  => '[0-9]+', 
        ), 
        'defaults' => array(
         'controller' => 'Album\Controller\Album', 
         'action'  => 'index', 
        ), 
       ), 
      ), 
     ), 
    ), 

    'view_manager' => array(
     'template_path_stack' => array(
      'album' => __DIR__ . '/../view', 
     ), 
    ), 
); 
+0

Vous avez une idée sur les routages ZF2? –

+0

Ce n'est pas le routage c'est HTACCESS LIRE ALBUM TUTORIEL – Ivan

+0

S'il vous plaît envoyer votre fichier vhost aussi si vous le pouvez. Cela peut être quelque chose comme AllowOverride est défini sur none (dans ce cas le .htaccess n'est jamais exécuté) ou vous pointez sur le mauvais dossier? – Adrian

Répondre

2

Le contenu du fichier .htaccess fourni est le suivant;

RewriteEngine On 
# The following rule tells Apache that if the requested filename 
# exists, simply serve it. 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do 
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work 
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution. 
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
RewriteRule ^(.*) - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

Il diffère très légèrement de votre copie, j'ai essayé votre fichier .htaccess sur un exemple de travail et il semble très bien.

Le 404 est-il un serveur générique "à la recherche" 404 ou s'agit-il d'une page sur le thème ZF2?

Peut-être une suggestion idiote mais avez-vous essayé http://my-vhost.localhost/public ou http://my-vhost.localhost/public/album ???

Pour autant que je sais que vous ne devriez pas besoin d'appeler directement les fichiers .php

+0

Je vais poster VHOST – Ivan

+0

Vérifiez mon VHOST. – Ivan

2

Je ne suis pas sûr qu'il est trop tard pour répondre à cette question, comme Finbarr suggère d'essayer avec http://my-vhost.localhost/public ou http://my-vhost.localhost/public/album.

J'ai eu aussi le même problème chaque fois que je tape www.zf2-tutorial.loc il a toujours été redirigé vers la page principale de xampp.

Enfin je lis les commentaires Froom Finbarr j'ai changé à

http://www.zf2-tutorial.loc/zf2-tutorial/public/ 

après que le webspage: Bienvenue sur Zend Framework 2 a été chargé.

#the virtual host: 

NameVirtualHost *: 80

<VirtualHost *:80> 
DocumentRoot "C:\xampp\htdocs" 
ServerName localhost 
</VirtualHost> 

<VirtualHost *:80> 
<DocumentRoot "C:/xampp/htdocs/zf2-tutorial/public" 
ServerName www.zf2-tutorial.loc zf2-tutorial.loc 
ServerAlias zf2-tutorial.loc 
<Directory "C:/xampp/htdocs/zf2-tutorial/public"> 
    DirectoryIndex index.php 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
</Directory> 
</VirtualHost> 

dans l'hôte, j'ai fait plusieurs combinaisons à essayer de savoir lequel était correcte.

127.0.0.1 localhost 
127.0.0.1 www.zf2-tutorial.loc zf2-tutorial.loc 
127.0.0.1 www.zf2-tutorial.loc zf2-tutorial.loc localhost 
127.0.0.1 www.zf2-tutorial.loc localhost 
127.0.0.1 www.zf2-tutorial.loc 
127.0.0.1 zf2-tutorial.loc localhost 
127.0.0.1 zf2-tutorial.loc 

apache (httpd conf) a ce paramètre certaines personnes suggèrent de supprimer il balise de hachage, mais je ne travaillais pas pour moi, donc parti comme je l'ai trouvé:

# Virtual hosts 
# Include conf/extra/httpd-vhosts.conf 

Egalement dans la même fichier (httpd conf) Je change la AllowOverride None à AllowOverride FileInfo comme suit:

<Directory /> 
AllowOverride FileInfo 
Require all denied 
</Directory> 

re a commencé le xampp et il a été affiché les félicitations page web.