1

我有一个网站,我想要像这样的 URLSiteURL/about.html.

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

'showScriptName'=>false如果在文件中注释此代码config/main.php,那么它的工作正常,现在我的登录会话已保存并且我们没有过期但是现在我的 URL 变成了这样SiteURL/index.php/about.html

但我想要像这样的网址about.html.

我还有另一个用于游戏选项的控制器,其 URL 类似于: http: //www.demo.com/index.php/Games/info/9.html但我想要在这个“ black-hook”是游戏的名称。

'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>'
           ), 
     ),

*SiteURL = http://www.demo.com

4

1 回答 1

0

首先要将 .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>'
           ),
     ),

其次,为了在 URL 中隐藏 index.php(称为入口脚本),除了在此处更改配置之外,您还需要更改 apache/nginx 服务器中的配置。

使用以下内容创建文件 /.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

接下来验证AllowOveride All您的 apache 配置文件中是否存在您的 app 目录您也可以使用 Directory 元素将上述配置直接添加到您的 apache 配置文件中,而无需使用 .htaccess 。 注意:为此,您需要在 apache 配置中启用重写引擎,您可以使用以下命令集

a2enmod rewrite

最后重启apache2后

/etc/init.d/apache2 restart

或者

service apache2 restart
于 2014-06-22T18:22:50.763 回答