之间的操作有什么区别.和 ^ 和 ^(.*)$? [英] What is the difference in operation between . and ^ and ^(.*)$?
本文介绍了之间的操作有什么区别.和 ^ 和 ^(.*)$?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
操作上有什么区别:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
和
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
和
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
我知道."表示字符串的任何字符和^"开头.
I know that "." means any character and "^" beginning of string.
感谢回复!
推荐答案
首先让我们了解着陆页是如何匹配的.
First let's understand how landing page is matched.
登陆页面 URI 模式是 .htaccess 中的 ^$
,Apache 配置中的 ^/$
.因此,您可以安全地普遍使用 ^/?$
.
For landing page URI pattern is ^$
in .htaccess, ^/$
in Apache config. Thus you can safely use ^/?$
universally.
- 您的第一个重写规则将匹配每个网址(包括着陆页,即
http://domain.com/
). - 您的第二个重写规则将匹配每个网址(着陆页除外).由于单个 DOT 将不匹配
^$
URI 模式. - 你的第三个重写规则也将匹配每个 URL(包括登陆页面,即
http://domain.com
),但有一个不必要的捕获组和只是^
.
- Your first rewrite rule will match every URL (including landing page i.e.
http://domain.com/
). - Your second rewrite rule will match every URL (except landing page). As single DOT will not match
^$
URI pattern. - Your third rewrite rule will also match every URL (including landing page i.e.
http://domain.com
) but has an unnecessary capturing group and longish version of just^
.
这篇关于之间的操作有什么区别.和 ^ 和 ^(.*)$?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文