tags:

views:

51

answers:

1

Example current URL http://www.domain.com/subdomain/install/finish.php

I use this code to get the current URL.

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

Now I want to get the URL looks like http://www.domain.com/subdomain if there don't have sub-folder it will read like http://www.domain.com

Let me know.

+2  A: 

I don't really understand your requirement, but take a look at parse_url().

It splits a URL into the following fragments:

* scheme - http://
* host www.domain.com
* port 
* user
* pass
* path /subdomain/install/finish.php
* query  
* fragment  
Pekka
@Pekka, I wish I could upvote this, but i've got no more votes today :( good answer!
Jacob Relkin