What are common ways to achieve SEO-friendly URLs in PHP websites?
SEO-friendly URLs in PHP websites can be achieved by using descriptive keywords in the URL structure, keeping URLs short and readable, using hyphens to separate words, and avoiding special characters or symbols. One common way to achieve this is by using URL rewriting techniques, such as mod_rewrite in Apache, to rewrite dynamic URLs into static, keyword-rich URLs.
// Enable mod_rewrite in .htaccess file
RewriteEngine On
// Rewrite rule to convert dynamic URLs to SEO-friendly URLs
RewriteRule ^products/([0-9]+)/([a-zA-Z0-9_-]+)$ product.php?id=$1&name=$2 [NC,L]
Related Questions
- What are some common pitfalls when using PHP to generate HTML elements like tables and divs?
- Is it better to use separate CSS/HTML files or a modular system for dynamically adjusting layouts based on browser compatibility using PHP?
- How can syntax errors in MySQL queries be identified and resolved in PHP code?