[英]How to get clean website url with php?
I'm using $wsurl as my websites clean url $wsurl = 'http://'. 我将$ wsurl用作网站的干净URL $ wsurl ='http://'。 $_SERVER['HTTP_HOST'] .
$ _SERVER ['HTTP_HOST']。 '/';
'/'; But recently when I want to echo it from websites admin panel it gave me result:
但是最近,当我想从网站管理面板中回显它时,它给了我结果:
http://localhost/admin/ >http://localhost/?page=166 http:// localhost / admin / > http:// localhost /?page = 166
instead of 代替
http://localhost/?page=166 HTTP://本地主机/页= 166
More Detailed 更详细
What i use: <a target="_blank" href="><?=$wsurl?>?page=<?=$new_id?>">Link</a>
我使用的是:
<a target="_blank" href="><?=$wsurl?>?page=<?=$new_id?>">Link</a>
What i get as html output <a target="_blank" href=">localhost/?page=170">Link</a>
我得到的HTML输出
<a target="_blank" href=">localhost/?page=170">Link</a>
But when i click it from admin panel, it opens page localhost/admin>http://localhost/?page=170
(instead of http://localhost/?page=170
) which doesn't exist at all 但是,当我从管理面板中单击它时,它将打开根本不存在的页面
localhost/admin>http://localhost/?page=170
(而不是http://localhost/?page=170
)
How to deal with that problem? 该如何处理?
I want to get websites main url from everywhere within ws. 我想从ws的任何地方获取网站的主要URL。 For ex, if i'm in admin panel http://localhost/admin/index.php the $wsurl will be http://localhost/
例如,如果我在管理面板http://localhost/admin/index.php中,则$ wsurl为http:// localhost /
If my admin panels url looks like http://mydomain.com/admin/index.php the $wsurl will be http://mydomain.com/ 如果我的管理面板网址看起来像http://mydomain.com/admin/index.php,则$ wsurl将是http://mydomain.com/
If you are facing issues like that then you can try this : 如果您遇到类似问题,可以尝试以下方法:
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.parse_url($url, PHP_URL_HOST) . '/';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.