为何网站链接不显示index.php,却以长尾形式呈现?
- 内容介绍
- 文章标签
- 相关推荐
本文共计614个文字,预计阅读时间需要3分钟。
使用Yii框架隐藏index.php的方法如下:
1. 在网站根目录下添加`.htaccess`文件。
2.修改`config/web.php`配置文件。
3.将`.htaccess`中的`AllowOverride`设置为`All`。
具体步骤:
1. 在网站根目录下创建或编辑`.htaccess`文件。
2.在`.htaccess`文件中添加以下代码:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !=index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L]3.打开`config/web.php`文件,找到以下配置行:
php 'components'=> [ // ... 'urlManager'=> [ 'enablePrettyUrl'=> true, 'showScriptName'=> false, // ... ], // ... ],4.确保上述配置中的`enablePrettyUrl`和`showScriptName`设置为`true`和`false`。
5.保存所有更改。
现在,访问网站时,index.php将被隐藏,URL将不会显示index.php。
yii url隐藏index.php的方法:首先在web根目录下增加“.htaccess”文件;然后修改配置“config/web.php”;最后将“AllowOverride None”修改为“AllowOverride All;”即可。
推荐:《PHP视频教程》《yii教程》
Yii 框架开启 URL 美化,隐藏 index.php [ 2.0 版本 ]
url美化
目的:将 localtest/yii/web/index.php?r=hello/index
美化成:localtest/yii/web/hello/index
这里我是用的wampserver新建了一个localtest站点(详情可点击这里点击这里),并将yii的basic文件夹重新命名为yii。
对比上面的两个地址,其实就是把index.php?r=隐藏。
这里分两步:
1、增加.htaccess文件
在web根目录下增加.htaccess文件,内容为:
RewriteEngine On DirectoryIndex index.html index.php # 如果是一个目录或者文件,就访问目录或文件 RewriteCond %{REQUEST_FILENAME} !-d #如果文件存在,就直接访问文件,不进行下面的RewriteRule RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php
无法直接创建.htaccess,可以先创建一个txt文件,然后另存为…,保存为文件名为.htaccess,保存类型选择所有文件即可。
2、配置config/web.php 在config/web.php中的components数组中增加这一项:
'urlManager' => [ // //开启url美化 'enablePrettyUrl' => true, // //隐藏index.php 'showScriptName' => false, // //禁用严格匹配模式 'enableStrictParsing' => false, // //url后缀名称 // 'suffix'=>'.html', 'rules' => [ ], ],
这时,可以将URL中的index.php?r=删除,如果出现404报错,可以查看服务器的配置,我用的是phpstudy中集成的apache 需要检查一下配置
conf\localtest/yii/web/hello/index
来访问 localtest/yii/web/index.php?r=hello/index
以上就是yii url隐藏index.php的详细内容,更多请关注自由互联其它相关文章!
本文共计614个文字,预计阅读时间需要3分钟。
使用Yii框架隐藏index.php的方法如下:
1. 在网站根目录下添加`.htaccess`文件。
2.修改`config/web.php`配置文件。
3.将`.htaccess`中的`AllowOverride`设置为`All`。
具体步骤:
1. 在网站根目录下创建或编辑`.htaccess`文件。
2.在`.htaccess`文件中添加以下代码:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !=index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L]3.打开`config/web.php`文件,找到以下配置行:
php 'components'=> [ // ... 'urlManager'=> [ 'enablePrettyUrl'=> true, 'showScriptName'=> false, // ... ], // ... ],4.确保上述配置中的`enablePrettyUrl`和`showScriptName`设置为`true`和`false`。
5.保存所有更改。
现在,访问网站时,index.php将被隐藏,URL将不会显示index.php。
yii url隐藏index.php的方法:首先在web根目录下增加“.htaccess”文件;然后修改配置“config/web.php”;最后将“AllowOverride None”修改为“AllowOverride All;”即可。
推荐:《PHP视频教程》《yii教程》
Yii 框架开启 URL 美化,隐藏 index.php [ 2.0 版本 ]
url美化
目的:将 localtest/yii/web/index.php?r=hello/index
美化成:localtest/yii/web/hello/index
这里我是用的wampserver新建了一个localtest站点(详情可点击这里点击这里),并将yii的basic文件夹重新命名为yii。
对比上面的两个地址,其实就是把index.php?r=隐藏。
这里分两步:
1、增加.htaccess文件
在web根目录下增加.htaccess文件,内容为:
RewriteEngine On DirectoryIndex index.html index.php # 如果是一个目录或者文件,就访问目录或文件 RewriteCond %{REQUEST_FILENAME} !-d #如果文件存在,就直接访问文件,不进行下面的RewriteRule RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php
无法直接创建.htaccess,可以先创建一个txt文件,然后另存为…,保存为文件名为.htaccess,保存类型选择所有文件即可。
2、配置config/web.php 在config/web.php中的components数组中增加这一项:
'urlManager' => [ // //开启url美化 'enablePrettyUrl' => true, // //隐藏index.php 'showScriptName' => false, // //禁用严格匹配模式 'enableStrictParsing' => false, // //url后缀名称 // 'suffix'=>'.html', 'rules' => [ ], ],
这时,可以将URL中的index.php?r=删除,如果出现404报错,可以查看服务器的配置,我用的是phpstudy中集成的apache 需要检查一下配置
conf\localtest/yii/web/hello/index
来访问 localtest/yii/web/index.php?r=hello/index
以上就是yii url隐藏index.php的详细内容,更多请关注自由互联其它相关文章!

