优化Mode_Rewrite行
我可以优化这些线路吗?
RewriteRule ^contact/$ index.php?page=contact [L,QSA] RewriteRule ^service/$ index.php?page=service [L,QSA] RewriteRule ^ads/$ ads.php$1 [L,QSA] RewriteRule ^posts/$ posts.php$1 [L,QSA]
Could I Optimize those lines?
RewriteRule ^contact/$ index.php?page=contact [L,QSA] RewriteRule ^service/$ index.php?page=service [L,QSA] RewriteRule ^ads/$ ads.php$1 [L,QSA] RewriteRule ^posts/$ posts.php$1 [L,QSA]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以概括“页面”的事情。请记住,在大多数情况下,可维护性比更少的线路更重要。你不应该做得太过分。
我的修改是这样的:它寻找任何特定的路线。如果没有匹配项,最后一条规则将作为后备,并将页面名称附加到
index.php?page=
中。You could generalize the "page" thing. Keep in mind though that maintainability is more important than fewer lines in most cases. You should not over-do it.
My modification works like this: It looks for any specific route. If there is no match, the last rule acts as a fallback and appends the name of the page to
index.php?page=
.