我剛安裝了Yii2。我在這個框架中仍然是新手。當我使用名爲「Sample-Yii2」的作曲家創建新項目時,我必須打開「web」文件夾才能加載index.php。我只是好奇,如果這個index.php可以移動到根文件夾。但它不能。如何將加載到網頁文件夾
當我打開localhost/Sample-Yii2而不是loacalhost/Sample-Yii2/web時,如何獲得直接頁面?
我剛安裝了Yii2。我在這個框架中仍然是新手。當我使用名爲「Sample-Yii2」的作曲家創建新項目時,我必須打開「web」文件夾才能加載index.php。我只是好奇,如果這個index.php可以移動到根文件夾。但它不能。如何將加載到網頁文件夾
當我打開localhost/Sample-Yii2而不是loacalhost/Sample-Yii2/web時,如何獲得直接頁面?
在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>
如果您在開發中使用apache作爲web服務器,您應該在其他配置文件中正確配置apache配置文件中的虛擬主機。可能是不值得的。例如,如果你只是玩弄新的框架(Yii2)。嘗試使用PHP的內置服務器來代替。使用起來更簡單。
cd Sample-Yii2/web
php -S localhost:8000
localhost:8000
欲瞭解更多詳情,請參閱here
創建虛擬主機! http://httpd.apache.org/docs/2.2/vhosts/examples.html – MH2K9 2014-11-02 03:00:29
有沒有其他的方式?像修改配置? – 2014-11-02 03:16:34