Zend 框架 2 Htaccess [英] Zend Framework 2 Htaccess

查看:33
本文介绍了Zend 框架 2 Htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在 ZF2 中遇到了 htaccess 的问题.

Hello guys i have problem in ZF2 with htaccess.

我创建了 vhost 并且一切正常.当我打电话

I create vhost and all work good. when i call

my-vhost.localhost 一切正常,但是当我添加一些像/index.php 或/1234 这样的 uri 段时我得到 404.

my-vhost.localhost all work good but when i add some uri segment like /index.php or /1234 I get 404.

我在公共目录中编辑 .htaccess 并放入

I edit .htaccess in public dir and put

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

再一次,我有 404.知道我怎样才能减慢这个速度吗?

Bur again i have 404. Any idea how i can i slow this?

我的完整 .htaccess 是:

My full .htaccess is :

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]

虚拟主机

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

谁认为问题是路由检查我的路由模块.

Who think problem is routing check my route mod.

<?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',
        ),
    ),
);

推荐答案

我不确定现在回答这个问题为时已晚,因为 Finbarr 建议尝试使用http://my-vhost.localhost/publichttp://my-vhost.localhost/public/album.

Im not sure it is too late to answer this question, as Finbarr suggest to try with http://my-vhost.localhost/public or http://my-vhost.localhost/public/album.

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

I had also the same problem everytime I type www.zf2-tutorial.loc it always was redirected to xampp main page.

最后我读到了 Finbarr 的评论,我改成了

Finally i read the comments froom Finbarr i changed to

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

之后网页:Welcome to Zend Framework 2 被加载.

after that the webspage: Welcome to Zend Framework 2 was loaded.

#the virtual host:

NameVirtualHost *:80

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>

在主机中,我做了几个组合,试图找出哪个是正确的.

in the host I made several combinations trying to find out which one was correct.

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) 有这个设置,有些人建议删除他的哈希标签,但我没有为我工作,所以我发现它就留下了:

the apache (httpd conf) has this settings some people suggest to delete he hash tag but I didn't work for me so left it as i found it:

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

也在同一个文件 (httpd conf) 中,我将 AllowOverride None 更改为 AllowOverride FileInfo,如下所示:

Also in the same file (httpd conf) I change the AllowOverride None to AllowOverride FileInfo as follows:

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

重新启动 xampp 并显示祝贺网页.

re started the xampp and it was displayed the congratulations web page.

这篇关于Zend 框架 2 Htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆