导航

apache重写URL时,排除静态资源

Posted on 2020-12-13 12:39  displaynick  阅读(295)  评论(0编辑  收藏  举报

THINKPHP项目部署的apache 上面时,如果为了隐藏入口文件配置了重写URL,会导致将静态资源的URL也解析成Controller/Method,导致触发模块不存在

所以在URL重写配置中,需要排除静态文件目录,例如:(static|upload),...

在项目根目录下的.htaccess配置如下:

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteBase /tp
RewriteCond $1 !^(plugs|uploads|static)
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>