dongyirong3564 2014-04-08 16:39
浏览 25
已采纳

如何捕获指向不存在的页面/文件的URL? [关闭]

How to capture URL that points to non-existent page/file?

Lets say users enters a url like www.myserver.com/randomString, I would like to redirect the page to index.php, but also capture the "randomString"? I'm aware .htaccess can do the redirect on file not found, but what abotu the URL capture?

  • 写回答

2条回答 默认 最新

  • douhun8647 2014-04-08 16:52
    关注

    Simple method:

    Use $_SERVER['HTTP_REFERER'] to find out previous address. It cannot be fully trusted since it can be manipulated by some agents.

    More complicated method:

    You may use router-like, let's say, index.php on DocumentRoot and hide it from URL. To elaborate, all the requests will pass from index.php. In your example, it will become www.myserver.com/index.php/randomString and with .htaccess you may hide index.php which will eventually become www.myserver.com/randomString.

    Then you may capture whatever you want just analyzing index.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站