简体   繁体   English

如何通过PHP获取/读取Meta Canonical中最干净的URL?

[英]How to get/read the cleanest url into Meta Canonical via PHP?

Given: old ugly urls like /somepage?ln=en are rewritten in htaccess to /en/somepage 鉴于:像/somepage?ln=en这样丑陋的旧网址/somepage?ln=en在htaccess中重写为/en/somepage
Given: used canonical meta tag, with this php script above it to fill in the tidy url: 鉴于:使用规范元标记,在它上面的这个PHP脚本填写整洁的网址:

How to make them like the canonical? 如何使它们像规范一样?

      <link rel="canonical" href="<?=$canonicalURL?>">

What ways can one parse the current url without any strings, or, delete the extra strings from the url and put it into the canonical url? 有什么方法可以解析当前网址没有任何字符串,或者从网址中删除额外的字符串并将其放入规范网址?

$url = parse_url('http://example.com/path/page?param=value');

print_r($url)

Array
(
    [scheme] => http
    [host] => example.com
    [path] => /path/page
    [query] => param=value
)

Then you could just do: 然后你可以这样做:

$url['scheme'] . '://' . $url['host'] . $url['path']

Or even: 甚至:

$url = 'http://example.com/path/page?param=value'; 
'http://example.com' . parse_url($url, PHP_URL_PATH)

Essentially, you just want to get rid of the query string from $extensions, correct? 基本上,你只是想从$ extensions中删除查询字符串,对吗?

<?php
$qsIndex = strpos($extensions, '?');
$extensions = $qsIndex !== FALSE ? substr($extensions, 0, $qsIndex) : $extensions;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM