dpyoh6553 2012-11-20 16:27
浏览 82
已采纳

获取请求URI PHP

I am struck in getting the URI in my wordpress application and lack of PHP knowledge is making my progress slow. I have this URL

http://abc.com/my-blog/abc/cde 

i need to create a URL something like

http://abc.com/my-blog/added-value/abc/cde

where http://abc.com/my-blog is the URL of my wordpress blog which i can easily get using following method

home_url()

i can use PHP $_SERVER["REQUEST_URI"] to get request URI which will come up as

/my-blog/abc/cde

and than i have no direct way to add value as per my requirement

is there any way to achieve this easily in PHP or Wordpress where i can get following information

  1. Home URL
  2. Rest part of the URL

so that in end i can do following

Home-URL+ custom-value+Rest part of the URL

My point of Confusion

  1. On my local set up $_SERVER["REQUEST_URI"] is giving me /my-blog/abc/cde, where /my-blog is installation directory of wordpress and i can easily skip first level.
  2. On production server its not same as /my-blog will not be part of the URL.
  • 写回答

5条回答 默认 最新

  • dragon012100 2012-11-20 16:40
    关注

    Very briefly:

    <?php
    
    $url = "http://abc.com/my-blog/abc/cde";
    
    $parts = parse_url($url);
    
    $path = explode("/", $parts["path"]);
    array_splice($path, 2, 0, array("added-part")); //This line does the magic!
    
    echo $parts["scheme"] . "://" . $parts["host"] . implode("/",$path);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度