2013-05-13 59 views
0

我想用mod_rewrite。我在這/var/www/.htaccess代碼Symfony mod_rewrite只有主路由工作

<IfModule mod_rewrite.c> 

    Options +FollowSymlinks 
    RewriteEngine On 
    #AllowOverride All 

    #Allow from All 
    #RewriteBase /WorldClock 
    #RewriteBase WorldClock/web/app.php 
    # Explicitly disable rewriting for front controllers 
    RewriteRule ^/web/app_dev.php - [L] 
    RewriteRule ^/web/app.php - [L] 

    # Fix the bundles folder 
    #RewriteRule ^(.*)$ WorldClock/web/app.php/test [QSA,L] 

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

</IfModule> 

如果行是註釋,意味着它做出內部服務器錯誤 我的項目是在/var/www/WorldClock/..文件夾CSS | JS | IMG我轉移到/var/www 如果我試圖進入localhost那麼它工作正常。但是,如果我在鏈接點擊此網址這樣http://localhost/info/12然後我得到

Not Found The requested URL /info.xml/12 was not found on this server. 

一切正常,沒有的.htaccess。 mod_rewrite在phpinfo()中打開;我使用symfony2和Ubuntu

回答

0

爲了我們能夠提供幫助,至少我們需要您的web服務器的配置。我認爲這只是web服務器配置不正確的問題。如果我的答案是關閉的,請用有意義的錯誤消息更新您的問題,即檢查您的error.log和更詳細的說明哪些路由可以工作,哪些不可以,因爲我不完全確定您是否可以訪問本地主機並查看默認的「It work's」頁面或項目的首頁,以及是否可以訪問您的資產?

/etc/apache2/sites-available/只需創建一個新的文件worldclock.conf

<VirtualHost *:80> 
    ServerName localhost 

    DocumentRoot /var/www/WorldClock/web 
    <Directory /var/www/WorldClock/web> 
     # enable the .htaccess rewrites 
     AllowOverride All 
     Order allow,deny 
     Allow from All 
    </Directory> 
</VirtualHost> 

現在你只需要啓用新的虛擬主機,然後重新啓動您的web服務器:

sudo a2ensite worldclock 

# When both hosts use localhost as ServerName there might be some problems 
# so we'll disable the default host, which we won't need anyway(?) 
sudo adissite default 

sudo service apache2 restart 

如果這只是你的開發環境您可以使用PHP的內部Web服務器(假設您已安裝5.4),這將緩解一些所需的工作,因爲您只需運行:php app/console server:run以使其運行。然後,您可以通過以下方式訪問您的應用:默認爲http://localhost:8000

要確定安裝了哪個PHP版本,請在您的終端中運行:php -v