How can mod_rewrite in Apache be utilized to manipulate URLs in PHP?
Mod_rewrite in Apache can be utilized to manipulate URLs in PHP by rewriting the URL before it is passed to the PHP script. This can be useful for creating user-friendly URLs, redirecting old URLs to new ones, or implementing URL routing in a PHP application.
```php
RewriteEngine On
RewriteRule ^products/([0-9]+)$ product.php?id=$1 [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 the PHP script to access the product ID from the URL parameter.
Keywords
Related Questions
- How can PHP developers ensure that the login box disappears after successful authentication and displays user-specific links instead?
- What are the advantages and disadvantages of storing dates as UNIX timestamps in MySQL compared to using DATE or TIMESTAMP data types?
- What are some best practices for structuring PHP code to efficiently handle tabular data calculations and avoid unnecessary complexity or errors?