问题
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.
- 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^
.
来源:https://stackoverflow.com/questions/33319815/what-is-the-difference-in-operation-between-and-and