我的目标是使用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也被启用。