douhuan1937 2010-12-15 08:40 采纳率: 0%
浏览 74
已采纳

我如何$ _GET正确的ID

picture.php

if (!isset($_GET['id'])) {
    header('location:/');
    exit();
} else if (isset($_GET['id'])) {
    print_r($_GET);
}

$_GET output

 Array ( [page] => picture ) 

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^([A-Za-z0-9-]+)/?$ /index.php?page=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)/picture/?$ /picture/?id=$1 [L]

URL format : http://local.com/42/picture/

Question : How to make the $_GET['id'] will print 42 and not the picture

  • 写回答

2条回答 默认 最新

  • dq05304 2010-12-15 09:00
    关注

    The L flag causes a re-injection of the already rewritten URL into the rewriting process. So when /42/picture/ gets rewritten to /picture/?id=42 it then gets rewritten to /index.php?page=picture.

    You can avoid this by putting a rule in front of your other rules that stops the rewriting process for every request that’s path can be mapped onto an existing file:

    RewriteCond %{REQUEST_FILNAME} -f
    RewriteRule ^ - [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置