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 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题