What potential pitfalls should be considered when manipulating URLs in PHP, such as ensuring the correct placement of subfolders?

When manipulating URLs in PHP, one potential pitfall to consider is ensuring the correct placement of subfolders. This is important because incorrect placement can lead to broken links or incorrect routing within your application. To avoid this issue, always use relative paths when constructing URLs to ensure that subfolders are properly accounted for.

// Example of constructing a URL with correct placement of subfolders
$baseUrl = 'http://example.com';
$subfolder = 'subfolder';
$page = 'index.php';

$url = $baseUrl . '/' . $subfolder . '/' . $page;

echo $url;