【问题标题】:What is the difference in operation between . and ^ and ^(.*)$?两者在操作上有什么区别。和 ^ 和 ^(.*)$?
【发布时间】:2016-01-24 00:31:04
【问题描述】:

两者在操作上有什么区别:

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]

我知道“。”表示任何字符和字符串的“^”开头。

感谢回复!

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    首先让我们了解着陆页是如何匹配的。

    着陆页 URI 模式在 .htaccess 中为 ^$,在 Apache 配置中为 ^/$。因此,您可以安全地普遍使用^/?$

    1. 您的第一个重写规则将匹配每个网址(包括着陆页,即http://domain.com/
    2. 您的第二个重写规则将匹配每个网址(着陆页除外)。因为单个 DOT 将不匹配 ^$ URI 模式。
    3. 您的第三个重写规则也将匹配每个 URL(包括着陆页,即 http://domain.com,但有一个不必要的捕获组和较长的版本,只是 ^

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 2011-04-06
      • 2017-11-26
      相关资源
      最近更新 更多