This useful article shows you what parts of a URL you can build with .htaccess server environmental variables.
URL Anatomy
Below I have named the various parts of a URL and given the corresponding global PHP variable. This is not an exahstive list as you can get usrrname passwords from a URL
https://user123:password1@video.quantumwarp.com:8080/subfolder/subfolder2/index.php?turnip=51&alien=54#myniceheading 1 2 3 4 5 6 7 8 9 10 ## PHP Variables ## $_SERVER['SERVER_PROTOCOL'] 1-2 (:// is not included) $_SERVER['HTTPS']; (This is a Boolean) $_SERVER['PHP_AUTH_USER'] 2-3 $_SERVER['PHP_AUTH_PW'] 3-4 (: and @ are not included) $_SERVER['SCRIPT_NAME']; 4-8 $_SERVER['PHP_SELF']; 4-8 $_SERVER['HTTP_HOST']; 4-6 $_SERVER['SERVER_NAME']; 4-6 $_SERVER['SERVER_PORT']; 6-7 (: is not included) $_SERVER['REQUEST_URI']; 7-10 (fragment might not be included) $_SERVER['QUERY_STRING']; 8-9 (? is not included) ## Part Names ## Protocol 1-2 Username 2-3 Password 3-4 Sub Domain 4-5 Domain 5-6 Port 6-7 Path 7-8 Query 8-9 Fragment 9-10 (some might refer to this as an Anchor)
Links
- URL Layout
- Anatomy of a URL | doepud.co.uk (Wayback Machine) - very useful article on this subject.
- What are the parts of a URL? | Articles | web.dev - What's the difference between a host, site and origin? What is an eTLD+1? This article explains.
- URL - Wikipedia - A uniform resource locator (URL).
- URI fragment - Wikipedia - The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document.
- PHP
- PHP $_SERVER | W3Schools
- $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.
- This has an online demo where you can see the output of these variables.
- $_SERVER - PHP Manual - Server and execution environment information
- parse_url - PHP Manual
- Parse a URL and return its components
- This will get the fragment from the URL.
- How to get the current full url (url + fragments) of the webpage in PHP? - Stack Overflow
- You will not be able to get the fragment portion of the URI back as it is used on the client only. If you need this you will manually have to send them to a server with some JavaScript.
- PHP $_SERVER | W3Schools