如何删除URL(/web/index.php)警予2,设置路由干净的URL参数? [英] how to remove url (/web/index.php) yii 2 and set route with parameter with clean url?
问题描述
第一个问题:
我已经删除的index.php
,但我想删除 /网络
也。这是我的的.htaccess
first question:
i already remove index.php
, but i want remove /web
also. this is my .htaccess
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
和这是配置/ web.php
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
它的正常工作,但它仍然使用 /网络
。
是否有可能删除 /网络
?
it's working fine, but it's still using /web
.
is it possible remove /web
?
第二个问题:
我不能设置参数路由将干净的网址,我的路线地址:: toRoute(['交易/ getrequestdetail /','ID'=&GT; 1]);
i can't set route with parameter with that clean url, my route Url::toRoute(['transaction/getrequestdetail/', 'id' => 1 ]);
怎样的路线应该是什么?以及如何使用2参数路线?
how the route should be ? and how with 2 parameter route ?
推荐答案
对于高级应用程序请按照下列步骤操作:
1)增加以下的htaccess
到前端/网络
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
2)添加以下的htaccess
到根文件夹
,其中应用程序的安装
2) Add the following htaccess
to root folder
where application is installed
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1
3)修改前端/配置/ main.php
用下面的顶部文件
use \yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());
4)请求组件
添加到组件阵列相同的文件中,即前端/配置/ main.php
4) Add the request component
to the components array in the same file i.e frontend/config/main.php
'components' => [
'request' => [
'baseUrl' => $baseUrl,
],
],
这是it.Now可以访问前端无网/ index.php文件
That's it.Now you can access the frontend without web/index.php
有关你的第二个问题,你需要为它编写规则在URL管理组件。
For you second question you need to write the rule for it in your URL manager component.
事情是这样的:
'urlManager' => [
'baseUrl' => $baseUrl,
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'transaction/getrequestdetail/<id>' => 'transaction/getrequestdetail',
),
],
这篇关于如何删除URL(/web/index.php)警予2,设置路由干净的URL参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!