Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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
Php YII URL如何生成新的URL_Php_Yii_Url Rewriting_Yii Routing - Fatal编程技术网

Php YII URL如何生成新的URL

Php YII URL如何生成新的URL,php,yii,url-rewriting,yii-routing,Php,Yii,Url Rewriting,Yii Routing,我有一个网站需要像SiteURL/about.html这样的URL。 我在config/main.php中更改了代码,但当我登录到该站点时,当我导航到任何其他页面时,会话就会过期 如果在config/main.php文件中注释此代码'showScriptName'=>false,则其工作正常,现在我的登录会话已保存,我们尚未过期,但现在我的URL变得像这样SiteURL/index.php/about.html 但是我想要像about.html这样的URL。 我还有另一个游戏控制器选项,URL是

我有一个网站需要像
SiteURL/about.html这样的URL。

我在
config/main.php
中更改了代码,但当我登录到该站点时,当我导航到任何其他页面时,会话就会过期

如果在
config/main.php
文件中注释此代码
'showScriptName'=>false
,则其工作正常,现在我的登录会话已保存,我们尚未过期,但现在我的URL变得像这样
SiteURL/index.php/about.html

但是我想要像about.html这样的URL。

我还有另一个游戏控制器选项,URL是这样的:但我想要像SiteURL/black-hook.html这样的URL,在这个“黑钩”是游戏的名称

'urlManager'=>array( 
          'urlFormat'=>'path', 
          'showScriptName'=>FALSE, 
          'rules'=>array(
                 '<action>'=>'site/<action>',
                 '<view>'=>'array('site/page')',
                 '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                 '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                 '<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
           ), 
     ),
'urlManager'=>数组(
“urlFormat'=>“路径”,
'showScriptName'=>FALSE,
'规则'=>数组(

首先要将.html附加到页面中,您需要在urlManager中使用伪url后缀选项

这可以通过如下方式将
'urlSuffix'=>'.html'
添加到
urlManager
配置中来实现

'urlManager'=>array( 
          'urlFormat'=>'path', 
          'showScriptName'=>false, 
           'urlSuffix'=>'.html',
          'rules'=>array(
                 '<action>'=>'site/<action>',
                 '<view>'=>'site/page',
                 '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                 '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                 '<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
           ),
     ),
接下来验证apache配置文件中是否存在应用程序目录的
allowveride All
,也可以使用directory元素直接将上述配置添加到apache配置文件中,而不使用.htaccess。 注意:要使其正常工作,您需要在apache配置中启用重写引擎,您可以使用以下命令集执行此操作

a2enmod rewrite
之后,最后重新启动apache2

/etc/init.d/apache2 restart


发布您的.htaccess please.Btw.why“.html”?Yii是基于PHP的!嗨,谢谢您的支持,我已经尝试过了,但有一段时间用户变成了会话注销,用户无法登录网站,您能帮我一下吗?我在这里遗漏了什么吗?
/etc/init.d/apache2 restart
service apache2 restart