首页 > 解决方案 > Php get website url after https:// or www. or subdomain

问题描述

I want to get the correct URL with PHP without any error, my links example:

https://example.com/
https://example.com/search/
https://example.com/search/?q=test

https://it.example.com/
https://it.example.com/search/
https://it.example.com/search/?q=test

so i want to get all link if is https://example.com/ show example.com if is https://example.com/search/ show example.com/search/ if is https://it.example.com/search/?q=test show example.com/search/?q=test etc.. without any error. thanks

标签: php

解决方案


看起来你需要$_SERVER['REQUEST_URI']

$link = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

也可以查看 PHP 文档: http: //php.net/manual/en/reserved.variables.server.php

这将返回没有 https 的 HTTP 主机,并且还会为您提供带有查询字符串等的 request_uri。

parse_url()还将为您提供每个元素,然后您可以构建所需的字符串:

http://php.net/manual/en/function.parse-url.php


推荐阅读