dshfjsh_5455 2012-07-10 19:22
浏览 64
已采纳

检索wordpress页面的原始URL

I know that, wordpress redirects closely matched urls to its original url.However, I need to know the actual url at the very beginning of code execution. Is it possible?

1) If there is any method that takes a url as parameter and returns its original wordpress url , that would be great, but not sure, whether it exists or not. Is there something like that?

2) where in the code actually does this test and redirection please?

3) Is there any hook that I can use to add a plugin to control this situation?

Thanks in advance.

Example:

Suppose, I have a post on this url: "http://mydomain.com/example-post-page"

Now if I try to access it via "http://mydomain.com/example-post-page/", it will redirect you to original first url. It is true for other several small changes in url, all will redirect you to the actual permalink url.

My goal is to control this redirection. That's why, when I am on "http://mydomain.com/example-post-page/" , I like to know(my code in on root index.php) whether this is the origianl permalink or is that something else, before it redirects.

  • 写回答

3条回答 默认 最新

  • doupang4126 2012-07-14 19:24
    关注

    Ok, At last I got it done in the following way and seems ok for me:

    1) Recieve approx url. 2) Make a cURL request using this approx url. 3) get response url. 4) return the response url.

    Code given below:

    function get_actual_url($approx_url){
    $curlObj = curl_init();
    curl_setopt($curlObj, CURLOPT_URL, $approx_url);
    curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curlObj, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curlObj, CURLOPT_ENCODING , "gzip");
    curl_setopt($curlObj, CURLOPT_TIMEOUT,180);
    
    $content = curl_exec($curlObj);
    
    $info = curl_getinfo($curlObj);
    curl_close($curlObj);
    
    if(!empty($info) && !empty($info["url"])){
        return $info["url"];
    }
    else {
        return $approx_url;
    }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘