2014-11-02 45 views
0

我剛安裝了Yii2。我在這個框架中仍然是新手。當我使用名爲「Sample-Yii2」的作曲家創建新項目時,我必須打開「web」文件夾才能加載index.php。我只是好奇,如果這個index.php可以移動到根文件夾。但它不能。如何將加載到網頁文件夾

當我打開localhost/Sample-Yii2而不是loacalhost/Sample-Yii2/web時,如何獲得直接頁面?

+0

創建虛擬主機! http://httpd.apache.org/docs/2.2/vhosts/examples.html – MH2K9 2014-11-02 03:00:29

+0

有沒有其他的方式?像修改配置? – 2014-11-02 03:16:34

回答

0

Apache's httpd.conf文件中或在虛擬主機配置中使用以下配置。請注意,您應該將path/to/basic/web替換爲basic/web的實際路徑。

# Set document root to be "basic/web" 
DocumentRoot "path/to/basic/web" 

<Directory "path/to/basic/web"> 
    # use mod_rewrite for pretty URL support 
    RewriteEngine on 
    # If a directory or a file exists, use the request directly 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    # Otherwise forward the request to index.php 
    RewriteRule . index.php 
    # ...other settings... 
</Directory> 

參考here。另請閱讀article

0

如果您在開發中使用apache作爲web服務器,您應該在其他配置文件中正確配置apache配置文件中的虛擬主機。可能是不值得的。例如,如果你只是玩弄新的框架(Yii2)。嘗試使用PHP的內置服務器來代替。使用起來更簡單。

  1. cd Sample-Yii2/web
  2. php -S localhost:8000
  3. 轉到瀏覽器並訪問localhost:8000

欲瞭解更多詳情,請參閱here

相關問題