URL 重写的常见应用场景包括:
example.com/index.php?id=123
重写为 example.com/article/123
。要实现 URL 重写,需要在 Apache 的配置文件 httpd.conf
中添加相应的规则。例如:
RewriteEngine on
RewriteRule ^/article/([0-9]+)$ /index.php?id=$1 [L]
除重写 URL,Apache 还支持直接对 URL 进行跳转。这在以下场景中非常有用:
要实现 URL 跳转,同样需要在 Apache 的配置文件中添加规则。例如:
Redirect 301 /old-page.html https://example.com/new-page.html
Apache 的 mod_rewrite 模块提供强大的 URL 重写和跳转功能,可以帮助开发者实现各种复杂的 URL 管理需求。