2013-08-20 189 views
1

你好家伙我在使用htaccess的ZF2中遇到问题。Zend Framework 2 Htaccess

我创建了虚拟主机,所有的工作都很好。当我打电话

我-vhost.localhost所有的工作很好,但是当我添加一些URI段类似的index.php或/ 1234 我得到404

我编辑的.htaccess公开目录,并把

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

布尔再次我有404.任何想法我怎么能减慢这一点?

我的全是的.htaccess:

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> 

谁想到的问题是路由检查我的路线国防部。

<?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

你有关于ZF2路线的想法? –

+0

这不是路由这是HTACCESS READ ALBUM TUTORIAL – Ivan

+0

如果可以,请发布您的vhost文件。它可能像AllowOverride设置为none(在这种情况下,.htaccess永远不会执行),或者您指向错误的文件夹? – Adrian

回答

2

附带的.htaccess文件的内容如下;

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] 

它从你的拷贝非常略有不同,我试图在工作示例.htaccess文件,它似乎罚款。

404是你得到一个通用的“服务器看”404还是它是一个ZF2主题页?

可能是一个愚蠢的建议,但你试过http://my-vhost.localhost/publichttp://my-vhost.localhost/public/album ???

据我知道你不应该需要调用.php文件直接

+0

我会发布VHOST – Ivan

+0

检查我的VHOST。 – Ivan

2

林不知道这是为时已晚来回答这个问题,因为财务巴雷建议尝试用 http://my-vhost.localhost/publichttp://my-vhost.localhost/public/album

我每次输入www.zf2-tutorial.loc时也遇到同样的问题,它总是被重定向到xampp主页面。

最后我读了评论弗鲁姆财务巴雷我改

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

的webspage后:欢迎Zend框架2装载。

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

在主机我做了几个组合试图找出哪一个是正确的。

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 

的阿帕奇(httpd的的conf)有这个设置有些人建议删除他散列标签,但对我来说离开它,因为我发现我没有工作:

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

另外在同一文件(httpd的CONF)我改变的AllowOverride None(无)的AllowOverride FileInfo的如下:

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

重新启动XAMPP并将其显示在祝贺的网页。