2013-08-20 194 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並將其顯示在祝賀的網頁。