为MVC前端控制器设置.htaccess

时间:2019-03-30 07:46:03

标签: apache .htaccess

我有一个关于设置前端控制器所需的.htaccess文件的简单问题。 此配置有什么区别:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php/$1 [L]

及其他:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !\.(css|js|icon|zip|rar|png|jpg|gif|pdf)$ index.php [L]

1 个答案:

答案 0 :(得分:1)

RewriteRule ^(.+)$ index.php/$1 [L]

此规则将所有请求转发到index.php文件,无论请求的文件类型如何

RewriteRule !\.(css|js|icon|zip|rar|png|jpg|gif|pdf)$ index.php [L]

此规则只会将请求转发到不在指定扩展名列表中的index.php。