Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
yii从url字符串中删除子文件夹_Yii - Fatal编程技术网

yii从url字符串中删除子文件夹

yii从url字符串中删除子文件夹,yii,Yii,我正在尝试从我在Yii上的url中删除/site/和/user/。我尝试添加此代码 'contact' => array('site/contact', 'caseSensitive'=>false), 但我还是不能让它工作。我试图让我所有的静态页面看起来像mydomain.com/about.html 以下是我想更改的一些url /site/page?view=about ==> mydomain.com/about.html /site/contact.html ==&g

我正在尝试从我在Yii上的url中删除/site//user/。我尝试添加此代码

'contact' => array('site/contact', 'caseSensitive'=>false),
但我还是不能让它工作。我试图让我所有的静态页面看起来像
mydomain.com/about.html

以下是我想更改的一些url

/site/page?view=about ==> mydomain.com/about.html
/site/contact.html ==> mydomain.com/contact.html
/user/login.html ==> mydomain.com/login.html
这是我到目前为止想要的

 'urlManager'=>array(
                'urlFormat'=>'path',
                'urlSuffix'=>'.html',
                'rules'=>array(
                    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                    '<action:.*>'=>'site/<action>',
                    'user/<controller:\w+>/<action:\w+>'=>'user/<controller>/<action>',
                ),
                'showScriptName' => false,
            ),
'urlManager'=>数组(
“urlFormat'=>“路径”,
'urlSuffix'=>'.html',
'规则'=>数组(
“/”=>“/视图”,
'//'=>'/',
'/'=>'/',
''=>'站点/',
'user/'=>'user/',
),
'showScriptName'=>false,
),
这是我的.htaccess

# Turning on the rewrite engine is necessary for the following rules and features
# FollowSymLinks must be enabled for this to work
<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
</IfModule>

# Unless an explicit file or directory exists, redirect all request to Yii entry script
<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php
</IfModule>
#以下规则和功能需要打开重写引擎
#必须启用以下符号链接才能使其工作
选项+FollowSymlinks
重新启动发动机
#除非存在显式文件或目录,否则将所有请求重定向到Yii条目脚本
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。index.php

似乎在应用
main
user
的规则之前保留了一些规则。第三个
'/'=>'/'
始终匹配任何路由,并在URL中保留控制器和操作的ID。由于应用了第一个匹配的规则,所以以下所有规则都没有意义

您应该将规则移动到
rules
数组
CUrlManager
的顶部。假设
main
user
是控制器的ID,它们可能如下所示:

'rules' => array(
    '<view:(about)>' => 'site/page'
    '<action:(contact)>' => 'site/<action>',
    '<action:(login)>' => 'user/<action>',
    // the rest rules here
)
使用类似于
'=>'site/page'
的东西也会将
/contact.html
转换为
/site/page?view=contact
,并将
/login.html
转换为
/site/page?view=login
。因此,与这些URL匹配的所有其他规则将永远不会被应用,这对您来说是不可接受的

'<view:(about|guestbook|download)>' => 'site/page'