2013-04-11 51 views
1

這是.htaccessZend Framework 1 manual建議使用:Zend框架1周的.htaccess有子目錄,並沒有RewriteBase

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

我打算將網站發佈到子文件夾,例如:http://localhost/my-app/所以要走的路會將此行添加到文件中:

RewriteBase /my-app 

現在一切正常。

問題是子文件夾名稱會有所不同(甚至可能是空的 - >http://my-app.com/),我想有一個.htaccess文件,因爲我有一個自動部署的過程,在任何情況下工作。

那麼有沒有解決方案,重寫工作,而不指定RewriteBase


編輯:目錄結構

my-app/ 
    application/ 
    library/ 
    public/ 
     .htaccess 
     index.php 
     ... 
    tests/ 
+0

其中的.htaccess位於何處? 'http:// localhost/.htaccess'或'http:// localhost/my-app/.htaccess' – 2013-04-11 08:22:06

+0

@silentboy .htaccess位於'public'文件夾中。 Apache別名指向公用文件夾,因此'http:// localhost/my-app /'指向我的'public'文件夾。 – 2013-04-11 08:25:24

+0

'RewriteBase /'應該有幫助。如果沒有解決,你應該添加目錄結構。其實這個問題不是太大,但我必須知道我的應用程序樹的第一個分支 – 2013-04-11 08:28:12

回答

0

和公衆.htaccess應該沒有RewriteBase

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} -s [OR] 
    RewriteCond %{REQUEST_FILENAME} -l [OR] 
    RewriteCond %{REQUEST_FILENAME} -d 
    RewriteRule ^.*$ index.php [NC,L] 
</IfModule> 
+0

我試過了,但沒有奏效,但沒有理由讓它工作。 apache別名指向'public /'目錄,而不是'my-app'目錄。 – 2013-04-11 08:46:33

+0

因此,沒有定義'RewriteBase'也應該工作@Matthieu – 2013-04-11 08:50:44

+0

有了這個配置,這是行不通的。我最終得到了404「在此服務器上找不到所需的URL/my-app/inventory/project /。」並在Apache錯誤日誌中:「文件不存在:D:/ matthieu/my-app/public/inventory,referer:http:// localhost/my-app/index/welcome」 – 2013-04-11 09:11:50