╃巡洋艦㊣ 2011-03-10 16:27:50 7537次浏览 4条回复 3 1 0

总结一下隐藏index.php文件的步骤 1.开启apache的mod_rewrite模块

  • 去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符号
  • 确保中有“AllowOverride All”

2.在项目中的/protected/config/main.php中添加代码:

'components'=>array(
  ...
  'urlManager'=>array(
  'urlFormat'=>'path',
  'showScriptName'=>false,//注意false不要用引号括上
  'urlSuffix'=>'.html',
  'rules'=>array(
    'sites'=>'site/index',
  ),
),
...
),

3.在与index.php文件同级目录下添加文件“.htaccess”,内容如下:

Options +FollowSymLinks
  IndexIgnore */*
  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

这样就可以实现隐藏index.php入口文件了。

觉得很赞
  • 回复于 2012-12-06 18:06 举报

    这两者有区别吗???

  • 回复于 2015-05-09 19:53 举报

    教程清晰明了 赞!!!!

  • 回复于 2015-07-08 17:40 举报
    'rules'=>array(
        'sites'=>'site/index',
    ),
    

    这一句是必须得么?

    7 条回复
    回复于 2015-07-08 17:59 回复

    不是必须的,根据自己的实际情况写url规则。

    回复于 2015-07-09 09:34 回复

    谢谢你,还有个问题:'urlSuffix'=>'.html',这一句一般在什么时候使用?

    回复于 2015-07-09 09:40 回复

    这里设置的是url后缀。

    回复于 2015-07-09 09:49 回复

    我设置了这一条以后,会我请求moduleID/controllerID/actionID这样的路由的actionID后面加".html",但是我在视图里有写了/controllerID/actionID.html的链接却出现不能访问的提示,这个又是因为什么?提示是:Unable to resolve the request "order/index.html".这个异常是有YiiBase、CWebApplication等一些框架里的代码抛出来的。

    回复于 2015-07-09 09:53 回复

    请问你是使用Url::to或者createUrl生成的链接吗?

    回复于 2015-07-09 10:03 回复

    - -!!大部分是这样的:<a href="/product.html?id=<?php echo $row['product_id'];?>"

    回复于 2015-07-09 10:08 回复

    是不是应该用'Url::to'或者'createUrl'生成链接?

  • 回复于 2015-07-09 10:04 举报
    <a href="/product.html?id=<?php echo $row['product_id'];?>" target="_blank"><?php echo GlobalFunc::globalSubstr($row['name'],10);?></a>
    

    代码在回复里看不到,

    4 条回复
    回复于 2015-07-09 10:09 回复

    请使用markdown格式发帖!你的写法不对,不能用字符串拼接url

    回复于 2015-07-09 10:17 回复

    使用CHtml::link会好点吧?还是使用你说的'Url::to'或者'createUrl'?

    回复于 2015-07-09 10:23 回复

    你说的几种方式都可以,Url::to是yii2的写法。

    回复于 2015-07-09 10:38 回复

    嗯,谢谢你,我试试去,你是好人,谢谢啦。

您需要登录后才可以回复。登录 | 立即注册