How can mod_rewrite be used to create user-friendly URLs in PHP?
Mod_rewrite can be used in PHP to create user-friendly URLs by rewriting URLs in a more readable format. This can help improve SEO, make URLs easier to remember, and enhance the overall user experience. By using mod_rewrite rules in a .htaccess file, you can map user-friendly URLs to the actual PHP files or scripts on the server.
```php
RewriteEngine On
RewriteRule ^products/([0-9]+)/?$ product.php?id=$1 [NC,L]
```
In this example, the mod_rewrite rule will rewrite a URL like "example.com/products/123" to "example.com/product.php?id=123". This way, users see a user-friendly URL while the server processes the request correctly.
Related Questions
- What steps can be taken to troubleshoot and debug PHP scripts that are not functioning correctly on different servers?
- What is the difference between the PHP functions substr() and explode() in terms of extracting a substring from a string?
- What potential issues can arise from using multiple functions to display different months in a PHP calendar?