【发布时间】:2017-03-23 09:48:00
【问题描述】:
这是我的 nginx.conf 内容:
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
break;
}
rewrite_log on;
location ~ .*\.svn\/.* { return 405; }
location ~ .*\.php {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
location ~* \.(html|shtml|htm|inc|log)$ {
expires 1m;
}
location ~* \.(css|js)$ {
expires 1m;
}
location ~* ^.+\.(jpg|jpeg|gif|swf|mpeg|mpg|mov|flv|asf|wmv|avi|ico)$ {
expires 15d;
}
我将其中的一些更改为 Apache,如下所示:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
但是当我在url中隐藏/index.php/时,我无法加载我的静态资源(css、js、img.etc),如何将nginxlocation规则更改为Apache的?
【问题讨论】:
-
应该是
RewriteRule ^(.*)$ /index.php?/$1 [L]而不是RewriteRule ^(.*)$ /index.php/$1 [L]你忘了? -
我不熟悉 nginx 配置,但是位置部分看起来像是更改了
ExpiresByType的等效项,并且没有进行任何重写。也许,您必须将对 css、js、img 的引用更改为绝对地址(即带有前导斜杠),但可以肯定地说,您应该澄清“我无法加载我的 css、js、img”的真正含义。跨度>
标签: php apache .htaccess nginx