dquoj04882 2013-10-29 20:42
浏览 114
已采纳

重定向而不更改网址

I always suck at .htaccess I'm trying to have a website where all requests go though index.php but i'd like the URL to be like www.sample.com/home. effectively that url would load www.sample.com/index.php?page=home

Right now I have

 RewriteRule ^/([a-z0-9-]+) /index.php?page=$1 [NC,PT,L]

Which doesnt work even though regexr test shows it should. I temporarily changed it to r=301 so i could see the redirect and noticed that www.sample.com/home is redirecting to www.sample.com/index.php?page=/index.php :(

Any thoughts?

Note I've been searching for this for a while and I can't find a solution that actually works. It's not like this was my first stop.

  • 写回答

1条回答 默认 最新

  • douxiangui5011 2013-10-29 20:43
    关注

    Change your rule to:

    # external redirect from actual URL to pretty one
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
    RewriteRule ^ /%1? [R=301,L]
    
    RewriteRule ^([a-z0-9-]+)/?$ /index.php?page=$1 [QSA,L,NC]
    

    Reference: Apache mod_rewrite Introduction

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 调查 Vitis AI 中验证 .xmodel 量化后的正确性
  • ¥30 codelite全屏时file、setting那一行消失了
  • ¥15 gazebo-rviz教程
  • ¥15 付费求做一个自助抢单插件
  • ¥15 bat批处理,关于数据复制问题
  • ¥50 同步两个不同结果的array中某些属性
  • ¥15 悬赏15远程操控解决问题
  • ¥15 CST复制的模型无法单独修改参数?
  • ¥15 前端页面想做个定时任务,但是使用requestAnimationFrame,setinterval和settimeout都不行
  • ¥15 根据以下文字信息,做EA模型图