What is the difference in operation between . and ^ and ^(.*)$?

梦想的初衷 提交于 2019-12-31 04:25:14

问题


What is the difference in operation between:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

and

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

and

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

I know that "." means any character and "^" beginning of string.

Thanks for reply!


回答1:


First let's understand how landing page is matched.

For landing page URI pattern is ^$ in .htaccess, ^/$ in Apache config. Thus you can safely use ^/?$ universally.

  1. Your first rewrite rule will match every URL (including landing page i.e. http://domain.com/).
  2. Your second rewrite rule will match every URL (except landing page). As single DOT will not match ^$ URI pattern.
  3. 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 ^.


来源:https://stackoverflow.com/questions/33319815/what-is-the-difference-in-operation-between-and-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!