문제

Given: old ugly urls like /somepage?ln=en are rewritten in htaccess to /en/somepage
Given: used canonical meta tag, with this php script above it to fill in the tidy url:

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?

도움이 되었습니까?

해결책

Essentially, you just want to get rid of the query string from $extensions, correct?

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

다른 팁

$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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top