What are the potential pitfalls of using relative paths for CSS and JS files in PHP when using RewriteRule for URL rewriting?
When using RewriteRule for URL rewriting in PHP, using relative paths for CSS and JS files can lead to broken links and styling issues. To avoid this problem, it is recommended to use absolute paths for CSS and JS files to ensure that they are correctly loaded regardless of the rewritten URL.
<?php
// Define base URL for absolute paths
$base_url = "http://www.example.com/";
// Include CSS file with absolute path
echo "<link rel='stylesheet' href='" . $base_url . "css/style.css'>";
// Include JS file with absolute path
echo "<script src='" . $base_url . "js/script.js'></script>";
?>