doufu6423 2018-01-31 18:59
浏览 45
已采纳

基于调用资产的html文件URL传递资源

If i have an html file located at http://sample.com and that html file is loading in an asset with an ajax call, can the server intercept that asset and deliver a different asset without the html file changing the url or adding url parameters to the asset ur;?

example: http://sample.com/index.html?configID=567 has a config.json file being loaded with ajax like this: $.getJSON('config.json', function(data){});

can apache know that this config.json file is being requested by an html file that has a url parameter of configID=567 and pass back a response from config567.json instead of config.json?

I can't modify the javascript in the html file to read $.getJSON('config.json?configID=567', function(data){}); so I would like to just do the modifications on the server side.

I also have php running as well if there is a php solution for this without changing the html file to a php file.

  • 写回答

1条回答 默认 最新

  • duandianzhong8315 2018-01-31 19:11
    关注

    You seem to be looking for Referer-based Rewrite in Apache. The implementation details may differ for you, but you can try this to get different files depending on the ID:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} configID=(\d+)$
    RewriteRule ^config.json$ configs/config-%1.json
    

    The %1 part refers to the parenthesized group in the RewriteCond line.

    Alternatively, you can enable PHP-processing for json file type and implement the logic in the php:

    // config.json
    <?php
    $id = $_GET['configID'];
    header('Content-Type: application/json');
    echo get_config_from_database_by_id($id);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭