How do I remove the file extension in the HTML HEAD metadata of a canonical URL?
P粉752826008
P粉752826008 2023-09-14 17:05:06
0
1
523

I have a website that asks for files without file extensions. For example, the URL http://www.example.com/foo.php should simply access http://www.example.com/foo. < /p>

But please forgive me as I am new to PHP but I would also like the

This will display the full URL, including the file extension.

Is there anyone with more PHP knowledge than me who can modify the above line of code to exclude the file extension?

Thanks in advance!

P粉752826008
P粉752826008

reply all(1)
P粉493313067

You can try to use str_replace to remove the extension

$string_with_extension = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];

$extension = ".php";

$new_string = str_replace($extension,"",$string_with_extension);

Simply put, you just replace the extension with "" or nothing will get you the URL you want.

<link rel="canonical" href="<?php echo $new_string; ?>">
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template