Skip to content
PHP Logo

What role does mod_rewrite play in dynamically generating URLs for user-created pages?

Mod_rewrite plays a crucial role in dynamically generating URLs for user-created pages by allowing the server to rewrite URLs in a more user-friendly format. This is achieved by using rules in a .htaccess file to redirect requests to a PHP script that can then dynamically generate the appropriate content based on the URL parameters.

php
```php
RewriteEngine On
RewriteRule ^page/([0-9]+)/?$ page.php?id=$1 [L]
```

In this example, the mod_rewrite rule will rewrite URLs in the format "example.com/page/123" to "example.com/page.php?id=123", allowing for dynamic generation of content based on the ID parameter passed in the URL.