如何简化 .htaccess 重写规则
是否可以简化这些 RewriteRules?我的 .htaccess
文件中有数百个类似的条目,这似乎不是设置 410 标头的最佳方法。
RewriteRule ^pageID_9363511.html - [G]
RewriteRule ^pageID_9363511_2.html - [G]
RewriteRule ^ci_8819019/thumb_11725326.JPG - [G]
…
…
谢谢
Is it possible to simplfy these RewriteRules? I've hundreds of similar entries in my .htaccess
file and it seems not to be the best way to set a 410 Header.
RewriteRule ^pageID_9363511.html - [G]
RewriteRule ^pageID_9363511_2.html - [G]
RewriteRule ^ci_8819019/thumb_11725326.JPG - [G]
…
…
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用重写地图,如下所示:
然后您查找请求的 URI 路径如下所示:
唯一的简化是您不需要重复的
RewriteRule
和[G]
。使用 dbm 类型的重写映射,您甚至可以拥有 O(1) 而不是 O(n) 的访问时间。You could use a rewrite map like this:
Then you lookup the requested URI path like this:
The only simplification is that you don’t need the repetitive
RewriteRule
and[G]
. And with a rewrite map of the type dbm you could even have an access time of O(1) instead of O(n).摆脱所有这些重写规则并说:
现在只需创建一个 404.html 文件,它就会将所有丢失的文件发送到那里。 410 错误消息在实践中很少出现,因为它指的是丢失的服务器而不是丢失的文件: http://www.checkupdown.com/status/E410.html
Get rid of all those rewritrules and say:
Now just make a 404.html file and it will send all missing files to there. The 410 error message is rarely if ever shown in practice as it refers to a missing server as opposed to a missing file: http://www.checkupdown.com/status/E410.html