如何在Yii2中将基本网址:http://Domain/ProjectName/web/index.php更改为http://Domain/ProjectName。
答案 0 :(得分:0)
你应该在基本模板中的/web.php的app / config / main.php(在高级模板中)启用漂亮的URL
$config = [
//...
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
],
//...
for apache将此添加到ProjectName / web / .htaccess文件
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteBase /ProjectName/
# 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?r=$1 [L,QSA]
答案 1 :(得分:0)
假设您有以下目录结构:
/root
|
|--/logs // or any other folder
|--/html <-- this is where DOMAIN.com is pointing
|
|--/ProjectName
|
|--/assets
|--/web
|--// and other folder
您可以做的是将项目文件夹移到html
之外。然后只复制web
文件夹中应用的html
文件夹,并将其重命名为ProjectName
(或任何其他)。现在您的文件夹结构应如下所示:
/root
|
|--/logs // or any other folder
|--/html <-- this is where DOMAIN.com is pointing
|
|--/ProjectName
|
|--/assets
|--/css
|--/index.php <-- EDIT this one
|--// and other files you had in web folder
|--/ProjectName
|
|--/assets
|--/web
|--// and other folder
最后打开index.php
(上面指出的文件)并替换以下行:
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../config/web.php');
用这个:
$project_path = __DIR__ . '/../../PojectName';
require($project_path . '/vendor/autoload.php');
require($project_path . '/vendor/yiisoft/yii2/Yii.php');
$config = require($project_path . '/config/web.php');
就是这样。现在,您可以通过以下网址访问您的申请:http://DOMAIN/ProjectName