2015-03-02 105 views
0

我嘗試在URL中使用我的Symphony 2項目而沒有/ web slug。我已將以下內容添加到我的根文件夾(localhost/subdir)中的.htaccess文件中。Symfony2將localhost/subdir/web/app.php/action重寫爲localhost/subdir/action

<IfModule mod_rewrite.c> 
    Options +FollowSymlinks 
    RewriteEngine On 

    # Explicitly disable rewriting for front controllers 
    RewriteRule ^web/app_dev.php - [L] 
    RewriteRule ^web/app.php - [L] 

    # Fix the bundles folder 
    RewriteCond %{HTTP_HOST} ^localhost/subdir/$ 
    RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L] 

    RewriteCond %{HTTP_HOST} ^localhost/subdir/$ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    # Change below before deploying to production 
    #RewriteRule ^(.*)$ /web/app.php [QSA,L] 
    RewriteRule ^(.*)$ web/app_dev.php [QSA,L] 
</IfModule> 

這個腳本加載我的網頁,但沒有得到任何/web/bundle/mybundle/javascript//images/,或/css/文件。這些給我一個404錯誤。因爲在<head>標籤中,它表示/bundle/mybundle/javascript/沒有/web前綴。在web-profiler,調試工具欄等上也是如此。

如何修復我的.htaccess以使其工作?

+4

本網站有關的編碼,而不是有關服務器的配置,你應該嘗試另一種如http: //serverfault.com/ – pbenard 2015-03-02 08:34:24

回答

0

web /文件夾是根web目錄 所以你有一個配置錯誤,告訴你的apache有web作爲文檔根。在httpd.conf中。如:

<VirtualHost *:80> 
    ServerName name.localhost.com 
    DocumentRoot "/Projects/name/web" 
    <Directory "/Projects/name/web"> 
    Options Indexes FollowSymLinks 
    AllowOverride All 
    Allow from All 
    </Directory> 
</VirtualHost> 

否則例如您的parameters.yml與數據庫傳遞等可以訪問。

用於重寫app.php/app_dev.php的URL可能看起來IKE網/的.htaccess的conf:

# Use the front controller as index file. It serves as a fallback solution when 
# every other rewrite/redirect fails (e.g. in an aliased environment without 
# mod_rewrite). Additionally, this reduces the matching process for the 
# start page (path "/") because otherwise Apache will apply the rewriting rules 
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). 
DirectoryIndex app.php 




<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 
    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
    RewriteRule ^app.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] ##### this is the part that you  should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially 
    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 

    RewriteRule .? %{ENV:BASE}/app.php [L]  ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially 

</IfModule> 



<IfModule !mod_rewrite.c> 
    <IfModule mod_alias.c> 
     # When mod_rewrite is not available, we instruct a temporary redirect of 
     # the startpage to the front controller explicitly so that the website 
     # and the generated links can still be used. 
     RedirectMatch 302 ^/$ /app.php/ 
     # RedirectTemp cannot be used instead 
    </IfModule> 
</IfModule> 
+0

對不起,但我不想通過httpd.conf來做到這一點,因爲我將這個文件夾上傳到域文件夾,該項目將通過www.site.com/project訪問 – 2015-03-02 08:51:13