【问题标题】:How to change Nginx rewrite rule to Apache?如何将 Nginx 重写规则更改为 Apache?
【发布时间】: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


【解决方案1】:

应该是 RewriteRule ^(.*)$ /index.php?/$1 [L] ?

不是

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

【讨论】:

  • 你好,我尝试用RewriteRule ^(.*)$ /index.php/$1 [L]RewriteRule ^(.*)$ /index.php?/$1 [L]设置rewrite mod,效果是一样的。但是我没有在.htaccess 中设置相同的重写规则而不是httpd.conf,而是解决了这个问题。 ...我真的不知道为什么。
  • 如果您需要将代码放入httpd.conf,您必须将代码放入<Directory></Directory>,检查此blog,但最好将其添加到.htaccess,这样您就没有访问Apache的核心服务器配置文件httpd.conf
猜你喜欢
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
  • 2014-11-17
  • 2014-06-30
  • 2016-08-09
  • 2018-05-06
  • 2016-06-18
  • 2014-06-22
相关资源
最近更新 更多