thinkPHP Apache 优化url,隐藏index.php所需配置

例如原先路径为:http://localhost/ehome/index.php/Index/index

现在想把index.php去掉,优化缩短url的长度,变为http://localhost/ehome/Index/index

下面介绍在thinkPHP框架中,Apache服务器对这种url优化的配置:

1:首先,找到你的Apache服务器的httpd.conf文件,在该文件中配置加载mod_rewrite.so模块,具体操作是在此文件中找到 #LoadModule rewrite_module modules/mod_rewrite.so,去掉前面的#即可,代码如下:

LoadModule rewrite_module modules/mod_rewrite.so

2:在httpd.conf文件中,修改Apache所指向的网站目录下的AllowOverride 的值,llowOverride none  改   AllowOverride ALL以我的为例:

<Directory "D:/wamp/www/">
    #
    # 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 all<span style="color:#ffffff;">
</span>
    #
    # Controls who can get stuff from this server.
    #

#   onlineoffline tag - don't remove
    Order Deny,Allow
    Allow from all
    Allow from all

</Directory>
3:配置为httpd.conf文件后,接下来就是配置项目的config.php文件了,把URL_MODEL的值改为2

'URL_MODEL' => 2,   // URL模式——REWRITE模式
4:最后一步就是在网站的根目录下(与项目入口文件index.php同级)添加一个.htaccess文件,写相关配置,内容如下:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>


完成以上四步就大功告成了!

注:发现在第三步中,将URL_MODEL=>1的时候也是可以的,我用的是thinkphp3.1




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值