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 to avoid when developing a web form with MySQL integration in PHP?
- Are there any potential security risks associated with saving images from external URLs to a server using PHP?
- What are some recommended methods for handling file permissions and ownership issues when uploading files using PHP?