Reputation: 641
How could I get the information after my main url with php?
Like let's say I have a url like this:
http://www.myawesomedomain.com/about
How could I pull the about
part of that url out and use it in php?
I know you can use the $_GET[]
variable for url but I don't want to mess up the url. What is a quick and easy way to do this?
Upvotes: 1
Views: 366
Reputation: 224
learn more about preg_match here: https://www.php.net/preg_match
Upvotes: 1
Reputation: 1043
What you want to do is called Url Rewrite and can follow this guide to learn more.
If you look on the Internet, there are many examples.
Upvotes: 1
Reputation: 8606
The request url might include a query string. The easiest way to parse out just the path is to use parse_url.
echo parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH);
// prints "/about"
Upvotes: 1
Reputation: 93636
In PHP, use the parse_url
function.
Perl: URI
module.
Ruby: URI
module.
.NET: 'Uri' class
Upvotes: 1