regex - 正则表达式 (.htaccess) 中 ^(.*)$ 和 ^ 之间的区别

标签 regex .htaccess mod-rewrite

两者有什么区别:

RewriteRule ^ http://example.com/page.html   [R=301,L]

RewriteRule ^(.*)$ http://example.com/page.html [R=301,L]

最佳答案

这两条规则之间没有真正的区别,但为了简单起见,我更喜欢第一条规则。

由于您没有对匹配组中的 REQUEST_URI 执行任何操作,因此无需像在第二条规则中使用 ^(.*)$

区别在于正则表达式:

^      - means match line start (will always match)
^(.*)$ - means match whole URI with 0 or more characters and capture it in $1

关于regex - 正则表达式 (.htaccess) 中 ^(.*)$ 和 ^ 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19498566/

相关文章:

ruby-on-rails - 在 ruby​​ 中,如何检查不以 9 开​​头的社会安全号码?

javascript - 正则表达式完全匹配数字,而不是数字

apache - 使用htaccess更改文档根目录

php - .htaccess 将另一个规则覆盖到其他页面

php - 将html解析为php,htaccess提示下载

php - 重写我的主 Controller (home),所以我在URL中看不到它,这可能吗?

php - 使用 codeigniter 和 htaccess 删除 index.php 和 301 重定向

java - 如何使用正则表达式获取子字符串

regex - mod_rewrite regex 仅在某个字符串不存在时才匹配

java - 匹配每个单词的第一个字符