How can mod_rewrite be used to create more user-friendly URLs in PHP?
Mod_rewrite can be used in PHP to create more user-friendly URLs by rewriting URLs in a way that hides the underlying server-side script file names and parameters. This can make URLs easier to read and remember for users, as well as improve search engine optimization.
```php
RewriteEngine On
RewriteRule ^products/([0-9]+)/?$ product.php?id=$1 [NC,L]
```
In this example, the mod_rewrite rule rewrites a URL like "example.com/products/123" to "example.com/product.php?id=123". This allows for a more user-friendly URL structure while still directing the request to the appropriate server-side script.
Related Questions
- How can I properly format the values in the $create variable in PHP?
- How can a PHP script be structured to handle form submissions from a popup window and close the window simultaneously?
- In what scenarios would it be more appropriate to calculate age based on comparing birthdate and current date rather than using a formula in PHP?