douaikuai2715 2017-07-05 11:30
浏览 37
已采纳

too long


Consider that I am requesting this url for a JSON api response.

// url that user will type in the browser address bar   
example.com/api/user/0001

I have 2 Options:


Option A

The redirection will be like this. But The address in the browser will be the same like before.

example.com?get1=api&get2=user&get3=0001

The ?get1=xxxxxx and &get2=xxxxxx and is IMPORTANT. if there is more slashes (/) in the url it will add more GET request like this&get4=xxxxx &get5=xxxxx and so on.

Then I will get the exact information form the $_GET['reques'] method like this!

$var_request = $_GET['get1'];
$var_type    = $_GET['get2'];
$var_id      = $_GET['get3'];



Option B

The redirection will be like this. But The address in the browser will be the same like before.

example.com?request=api/user/0001

Then I will get the exact information by exploding the api/user/0001 like this

// Geting request by $_GET
$request = $_GET['request'];

// Exploding by the (/)
$api = explode("/", $request);

// Getting my desired information
$var_request = $api[0];
$var_type    = $api[1];
$var_id      = $api[2];



Remember: The URL will be same as before. It should not look like ?get= this. The url should be still example.com/api/user/0001 in the browser url bar.

  • 写回答

1条回答 默认 最新

  • dongyun234854 2017-07-05 12:10
    关注

    I think Option B will be easier to do this. Possible solution is-

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.+)$ ?request=$1 [L]
    

    It redirects - example.com/api/user/0001 to example.com?request=api/user/0001 Without changing the address in the url bar in you browser.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题