Apache结合Thinkphp实现伪静态的设置方法
2011-05-24 15:04
525 查看
1、要隐藏Thinkphp项目中index.php文件名,需在config.php中设置'URL_MODEL'=>2,并且需要在.htaccess 中隐藏index.php,前者依赖于后者,否则可能导致Thinkphp项目中模块无法正常访问。
2、设置了'URL_MODEL'=>2,并且在.htaccess也隐藏了index.php,普通的查看记录的URL就变为了这种形式:
http://localohost/News/view/id/45.html
复制代码
但这并不能满足我们的URL优化效果,因为更好的SEO优化地址可能是这种形式:
http://localohost/News/2009-11-04/45.html
cufflinks wholesale这就需要我们更好的手动的去做为静态了。
经过测试,以下方式不可取:
1、'URL_MODEL'=>2、.htaccess隐藏index.php,
添加Rewrite规则:
RewriteRule ^News/(.*)/([0-9]+)\.html$
/News/view/id/$2
复制代码
结果提示找不到模块,并且在根目录下的Discuz论坛为静态也失效,看来隐藏index.php后果很严重。
2、'URL_MODEL'=>2、.htaccess不隐藏index.php,这样都矛盾了,更不行了。
3、'URL_MODEL'=>1、.htaccess隐藏index.php,这样项目生产的路径无法找到模块,论坛和其他文件夹伪静态也失效了。
最后总结出一种成功的办法:
1、'URL_MODEL'=>1,不隐藏index.php,再在.htaccess添加规则:
RewriteRule ^News/$
index.php/News/
RewriteRule
^News/category([0-9]+).html$ index.php/News/category/classid/$1
RewriteRule ^User/$
index.php/User/
RewriteRule
^News/(.*)/([0-9]+)\.html$ index.php/News/view/id/$2
……
discount
nike air shoes
需要说明的是,URL转发地址要与'URL_MODEL'中设置对应,如果设置的URL_MODEL=0,那么转发地址就要相应的变为
RewriteRule
^News/category([0-9]+).html$
index.php?m=News&action=category&classid=$1
复制代码
形式。
这样,一下的经过优化的URL就可以正常访问了,也不印象其他的程序。
http://localhost/News/
http://localhost/News/category2.html
http://localhost/User/
http://localhost/News/2009-11-05/22.html
也就是说,不利用'URL_MODEL'=>2(设置后,“__APP__”就会自动隐藏index.php路径),不隐藏index.php,我们就可以更加灵活的控制URL 优化了。
有不对的地方请大家指正。
2、设置了'URL_MODEL'=>2,并且在.htaccess也隐藏了index.php,普通的查看记录的URL就变为了这种形式:
http://localohost/News/view/id/45.html
复制代码
但这并不能满足我们的URL优化效果,因为更好的SEO优化地址可能是这种形式:
http://localohost/News/2009-11-04/45.html
cufflinks wholesale这就需要我们更好的手动的去做为静态了。
经过测试,以下方式不可取:
1、'URL_MODEL'=>2、.htaccess隐藏index.php,
添加Rewrite规则:
RewriteRule ^News/(.*)/([0-9]+)\.html$
/News/view/id/$2
复制代码
结果提示找不到模块,并且在根目录下的Discuz论坛为静态也失效,看来隐藏index.php后果很严重。
2、'URL_MODEL'=>2、.htaccess不隐藏index.php,这样都矛盾了,更不行了。
3、'URL_MODEL'=>1、.htaccess隐藏index.php,这样项目生产的路径无法找到模块,论坛和其他文件夹伪静态也失效了。
最后总结出一种成功的办法:
1、'URL_MODEL'=>1,不隐藏index.php,再在.htaccess添加规则:
RewriteRule ^News/$
index.php/News/
RewriteRule
^News/category([0-9]+).html$ index.php/News/category/classid/$1
RewriteRule ^User/$
index.php/User/
RewriteRule
^News/(.*)/([0-9]+)\.html$ index.php/News/view/id/$2
……
discount
nike air shoes
需要说明的是,URL转发地址要与'URL_MODEL'中设置对应,如果设置的URL_MODEL=0,那么转发地址就要相应的变为
RewriteRule
^News/category([0-9]+).html$
index.php?m=News&action=category&classid=$1
复制代码
形式。
这样,一下的经过优化的URL就可以正常访问了,也不印象其他的程序。
http://localhost/News/
http://localhost/News/category2.html
http://localhost/User/
http://localhost/News/2009-11-05/22.html
也就是说,不利用'URL_MODEL'=>2(设置后,“__APP__”就会自动隐藏index.php路径),不隐藏index.php,我们就可以更加灵活的控制URL 优化了。
有不对的地方请大家指正。
相关文章推荐
- centos下Apache服务器ThinkPHP伪静态的设置方法
- ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法
- Apache和Nginx设置伪静态(URL Rewrite)的方法
- ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法
- Apache和Nginx设置伪静态(URL Rewrite)的方法
- thinkphp5行为扩展实现html静态缓存设置
- 两个IP实现IIS和Apache公用80端口的设置方法
- Apache下伪静态html(URL Rewrite)的设置方法
- 两个IP实现IIS和Apache公用80端口的设置方法
- php Apache 服务器实现伪静态的方法
- ubuntu 设置静态IP的实现方法
- thinkphp路由规则使用示例详解和伪静态功能实现(apache重写)
- thinkphp 静态缓存页面的设置方法
- apache中通过mod_rewrite实现伪静态页面的方法
- [强烈推荐] thinkphp iis7.5 win2008 上 设置虚拟静态 错误的解决方法 web.config
- aspnet_isapi.dll设置图文方法.net程序实现伪静态
- aspnet_isapi.dll设置图文方法.net程序实现伪静态
- Apache服务器中使用.htaccess实现伪静态URL的方法
- jquery ajax结合thinkphp的getjson实现跨域的方法