我的目標是使用Yii-2編寫Web應用程序。我在Ubuntu上使用Apache作爲我的本地Web服務器。目前,我想配置yii2 urlManager。而在配置/ web.php這樣寫:如何設置Yii2路由和Apache?
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
這是簡單的設置。在enablePrettyUrl工作正常,我可以使用url-link,如http://localhost/basic/web/index.php/nameOfController/AndAction。 但是,當我安裝showScriptName這不適合我工作正確。 我配置apache爲:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
並以我當然加入.htaccess文件到Web文件夾,使用此:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
我使用基本yii2-基本應用和運行服務器後,我可以打開網站,例如: localhost/basic/web/testController/testAction。 但我想要使用這樣的鏈接: localhost/basic/testController/testAction,最後一個例子我不使用文件夾web。
好的,謝謝所有讀過它的人。你有什麼想法我怎麼能解決這個問題? 謝謝。 並且mod_rewrite也被啓用。