How can PHP be used to redirect based on specific URL endings?
To redirect based on specific URL endings in PHP, you can use the $_SERVER['REQUEST_URI'] variable to get the current URL and then check if it ends with a specific string using the substr() function. If the condition is met, you can use the header() function to redirect to a new URL.
$current_url = $_SERVER['REQUEST_URI'];
if (substr($current_url, -4) == 'page') {
header('Location: https://example.com/newpage');
exit();
}
Keywords
Related Questions
- What are the alternatives to using YouTube's video player for embedding videos on a website?
- Is it possible to use Ajax to dynamically update input fields without reloading the page in PHP?
- How can developers optimize the performance of a web application that heavily relies on PHP and JavaScript interactions?