您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

隐藏index.php

2025/7/15 18:51:46发布16次查看
隐藏index.php
一、codeigniter
codeigniter和许多php框架一样,有个单一入口index.php,从url上看,显得很不友好。通过apache的rewirte,是可以隐藏掉的,实现伪url。
      打开codeigniter下system\application\config中的config.php  
      找到$config['index_page'] = index.php; 改为 $config['index_page'] = ;
      修改apache conf下的配置文件 httpd.conf
     # loadmodule rewrite_module modules/mod_rewrite.so
     去掉上面的#。(开启改功能)
    找到
#
    # possible values for the options directive are none, all,
    # or any combination of:
    #   indexes includes followsymlinks symlinksifownermatch execcgi multiviews
    #
    # note that multiviews must be named *explicitly* --- options all
    # doesn't give it to you.
    #
    # the options directive is both complicated and important. please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options 
    # for more information.
    #
    options indexes followsymlinks
    #
    # allowoverride controls what directives may be placed in .htaccess files.
    # it can be all, none, or any combination of the keywords:
    #   options fileinfo authconfig limit
    #
    allowoverride none
    #
    # controls who can get stuff from this server.
    #
    order allow,deny
    allow from all
将allowoverride none改为 allowoverride all
在工程的同级目录下,建立.htaccess文件 内容如下
    rewriteengine on
    rewritecond %{request_filename} !-f
    rewritecond %{request_filename} !-d
    rewritecond $1 !^(index\.php|images|robots\.txt)
    rewriterule ^(.*)$ /seam/index.php/$1 [l]
连接中既可以不比有index.php
二、thinkphp
去掉 url 中的 index.php thinkphp 作为 php 框架,是单一入口的,那么其原始的 url 便不是那么友好。但 thinkphp 提供了各种机制来定制需要的 url 格式,配合 apache .htaccess 文件,更是可以定制出人性化的更利于 seo 的 url 地址来。
.htaccess 文件是 apache 服务器中的一个配置文件,它负责相关目录下的网页配置。我们可以利用 .htaccess 文件的 rewrite 规则来隐藏掉 thinkphp url 中的 index.php 文件(即入口文件),这也是 thinkphp url 伪静态的第一步。
例如原来的 url 为:
http://127.0.0.1/index.php/index/insert
去掉 index.php 之后变为:
http://127.0.0.1/index/insert
如此一来,就变成了 http://服务器地址/应用模块名称/操作名称[/变量参数] 的常见 url 格式。
更改 apache httpd.conf 配置文件 提示:如果在虚拟主机商配置,请直接配置第三、四步,因为支持 .htaccess 的空间已经配置好了前面两步。
用编辑器打开 apache 配置文件 httpd.conf(该文件位于 apache 安装目录apache2conf),并按如下步骤修改,。
一、加载了 mod_rewrite.so 确认加载了 mod_rewrite.so 模块(将如下配置前的 # 号去掉):
loadmodule rewrite_module modules/mod_rewrite.so
二、更改 allowoverride 配置 更改需要读取 .htaccess 文件的目录,将原来的目录注释掉:
#
更改 allowoverride none 为 allowoverride fileinfo options ,更改后的配置如下所示: #
allowoverride fileinfo options
.htaccess 是基于目录来控制的, 该句即表示需要读取 .htaccess 文件的目录,要根据实际具体 apache 的解析目录来配置。虚拟主机如果提供 .htaccess 控制,一般都已经配置好了。
三、添加 .htaccess 文件 rewrite 规则 在需要隐藏 index.php 的目录下(本教程中为 e:/html/myapp,也即入口文件所在目录)创建 .htaccess 文件,并写入如下规则代码:
rewriteengine on  
#不显示index.php  
rewritecond %{request_filename} !-d 
rewritecond %{request_filename} !-f 
rewriterule ^(.*)$ index.php/$1 [qsa,pt,l] 
如果网站已经有 .htaccess 文件,在里面添加该段配置规则即可。如果不能创建该文件(windows 平台不能创建),可以从本站下载该文件,但该文件仅配置了隐藏 index.php 的规则,点击此处下载。
四、更改项目配置文件 编辑项目配置文件 conf/config.php ,将 url 模式配置为 2(rewrite模式):
    'url_model'=>2,
至此,各个配置已经完成。保存各配置文件后,重启 apache 服务器并删除 runtime 目录下的项目缓存文件,在浏览器访问隐藏 index.php 后的地址测试是否成功:
http://127.0.0.1/html/myapp/index/index
如果访问成功,那么利用 apache .htaccess 文件的 rewrite 规则隐藏 index.php 入口文件的配置就成功了。
附件列表
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product