dtdfj08626 2011-11-22 15:12 采纳率: 0%
浏览 50

修改.htaccess以使URL?variable = true更改为URL / variable?

I'm trying to change my .htaccess file so that if I go to:

http://www.example.com/index.php?login=true, it goes to http://www.example.com/login.

I currently have this code which removes index.php (which makes the above looks like http://www.example.com/?login=true).

RewriteEngine On
#remove index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^GET
  • 写回答

4条回答 默认 最新

  • dpzbh1779 2011-11-22 15:19
    关注

    I would setup your rewrite rule the other way around:

    RewriteEngine On
    RewriteRule ^login$ /index.php?login=true
    

    This way if a user browses to http://yourserver.com/login the actual page used is http://yourserver.com/index.php?login=true, but the first URL is shown in the browser. I assume this is what you are trying to achieve.

    If you really need to do it in the direction you asked for, you can try something like this:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^login=true$
    RewriteRule ^index\.php$ /login [L,R=301]
    

    This will fail of there are additional query parameters.

    If you want to redirect http://yourserver.com/index.php to http://yourserver.com you can simply add the following rewrite rule:

    RewriteRule ^index\.php$ / [L,R=301]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集