Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:04:29+00:00 2026-06-18T10:04:29+00:00

I am trying to get URL path and to save it as variable… $setURL

  • 0

I am trying to get URL path and to save it as variable…

$setURL = true;
$getDomain = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$getSubdomain = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

if ($setURL === true) {
    $result = 'http://'.parse_url($getDomain, PHP_URL_HOST) . '/';
    echo 'get domain';
} else {
    $result = 'http://'.parse_url($getSubdomain, PHP_URL_HOST).parse_url($getSubdomain, PHP_URL_PATH);
    echo 'get subdomain';
}

$siteURL = $result;

So basically if I defined variable $setURL = true; it will return correct URL for simple domain … http://domain-name.com

However else does not work as I want to… else is there for subdomains. So if I set $setURL = false; it should return following… http://domain-name.com/path/

But unfortunately it return more then that… It returns anything I type as URL…
http://domain-name.com/path/something/index.php it will return all of that as URL!

Please help me to fix this as I don’t have any ideas how I could manage to make it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:04:30+00:00Added an answer on June 18, 2026 at 10:04 am

    Formally, a subdomain precedes a domain name. For example, in ftp.debian.us, ftp is the subdomain.

    It sounds like what you want is the first path in the URI. You can use PHP’s explode() method to grab the first segment in the path.

    $uriparts = explode($_SERVER['REQUEST_URI']) // = '/path/to/somewhere/index.html'
    $path = $uriparts[1] // = 'path'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get an image from URL and save it to the isolated
I'm trying to get an image from an URL but when I save it
Im using The HTML Mobile Bolierplate and im trying to get the URL Address
I am trying to get the public URL of a given file stored in
Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
I am trying to get the requested URL from PHP. The URL is like
I am trying to get an image from URL in Android and set it
I'm trying to get an image sitting at a URL that is protected by
I'm trying to get an image off the internet from an URL in java.
I'm trying to get a custom handler to work for a specific URL (or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.