开发者

Get full vanify url with subdomains in PHP

开发者 https://www.devze.com 2023-03-28 15:32 出处:网络
My current URL looks like this : \'http://subdomain.domain.com/vanity/开发者_如何学编程url\' When I try to use PHP to get this URL:

My current URL looks like this : 'http://subdomain.domain.com/vanity/开发者_如何学编程url'

When I try to use PHP to get this URL:

$url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];

The var $url holds this:

 'http://domain.com/index.php?var1=vanity&var2=url';

I want to get the actual URL that is in the address bar. Is this possible?


What you are doing should work - the REQUEST_URI key should hold the un-rewritten URI. I guess what you are experiencing is a bug or bizarre misconfiguration in the Apache build you are working with.

Your best bet would be to print_r($_SERVER) and see if any of the keys in there hold what you are after - I have just done it on a heavily rewritten site I maintain and the following keys all contained the information you are after, either in part or as a whole:


SCRIPT_URL - has what REQUEST_URI should contain

SCRIPT_URI - has the entire URL including http://domain/

SCRIPT_NAME - has what REQUEST_URI should contain

PHP_SELF - has what REQUEST_URI should contain


Some of these seem odd to me that they should contain this (particularly PHP_SELF) but I think this is yet another good reason to not use mod_rewrite unless you absolutely have to...

0

精彩评论

暂无评论...
验证码 换一张
取 消