What are the potential pitfalls of using mod_rewrite in PHP scripts for URL redirection?
One potential pitfall of using mod_rewrite in PHP scripts for URL redirection is that it can lead to duplicate content issues if not properly configured. To avoid this, make sure to use canonical URLs to specify the preferred version of the URL for search engines.
// Redirect to canonical URL using mod_rewrite
if ($_SERVER['REQUEST_URI'] == '/old-url') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://www.example.com/new-url');
exit();
}
Related Questions
- What alternative methods can be used to allow users to select their preferred connection speed?
- How can the use of forward slashes instead of backslashes in file paths in PHP code help prevent issues when working with different operating systems?
- What are some potential causes for the error "Supplied argument is not a valid MySQL result" in PHP?