I have one question: my website would be localhost/carfinancing/index.php
I have different index.php page right now which is in HTML5 template and Yii is installed in "application" directory.
When I copy paste this directory then localhost/carfinancing/application/web/ shows my yii index page and localhost/carfinancing/application/web/online-car-loan-application shows another page.
Is there way for yii index file to show: localhost/carfinancing/application and for another page, to show: localhost/carfinancing/online-car-loan-application ? I mean to remove the '/web/' word from the url?
答案 0 :(得分:0)
看起来你有2个问题。我会努力回答这两个问题。
由于Yii2是MVC框架,因此它被设计为将所有请求都提供给控制器,然后控制器提供视图。如果您要将文件放在Web中直接查看,那么您将失去MVC的好处。
在config/web.php
$config = [
...
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
您还需要按如下方式设置.htaccess:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
然后将所有内容移出public_html
目录,并将web
目录中的所有内容放回public_html
。
如果您仍有问题,请参阅此文章:http://fellowtuts.com/yii/hide-or-remove-basicweb-from-url-in-yii-2-0/