如何使一个包罗万象的处理程序在.htaccess文件? [英] How to make a catch-all handler in an .htaccess file?

查看:111
本文介绍了如何使一个包罗万象的处理程序在.htaccess文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在那捕捉一切眼福直到那时一个.htaccess文件的末尾来创建一个规则。

I want to create a rule at the end of an .htaccess file that catches everything that failed to match up until then.

我怎么能这样做?

P.S。我已经尝试了一切:)其实,我没有,但可以肯定,似乎喜欢它!

更新:有些人回答与重写规则^ * $ 或等效的。 这不起作用!这将匹配的所有的,包括其他的好的网址。

Update: Some people are replying with RewriteRule ^.*$ or an equivalent. This does not work! It will match everything including the other 'good' URLs.

推荐答案

实际上有一些很好的答案,在这里了,但你有回应...

There are actually some good answers here already, but you have responded with...

但后来这匹配的一切,包括好东西。

But then this matches everything including the good stuff.

这是因为你没有告诉mod_rewrite的停止处理上的匹配。要做到这一点,用L标记每个规则,它告诉mod_rewrite的后说,如果这条规则匹配,停止处理任何进一步的规则。

This is because you aren't telling mod_rewrite to stop processing on a match. To do this, use the "L" tag after each rule, which tells mod_rewrite that "If this rule is matched, stop processing any further rules".

RewriteRule ^RSS/([^/\.]+)/?$ rss.php?Page=$1 [L]

您需要每个规则后,把这个。然后,当你把捕获的所有底,它只会在没有其他规则已被匹配命中。

You need to put this after EACH rule. Then, when you put the catch all at the end, it will only be hit if no other rule has been matched.

请注意:如果您还提供了未改写,如CSS,图片,JavaScript文件等资源 - 你是诚实最好不要再追所有,你会不会想重写它们的位置

NOTE: if you are ALSO serving up resources that are not rewritten, like CSS, images, javascript files - you are honestly better off not catching all as you wouldn't want to rewrite their locations.

这篇关于如何使一个包罗万象的处理程序在.htaccess文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆