【问题标题】:'nginx rewrite' to '.htacces rewrite''nginx 重写' 到 '.htaccess 重写'
【发布时间】:2014-08-09 20:35:32
【问题描述】:

我在正则表达式中非常糟糕,但在服务器配置中我是最差的。 所以任何帮助都会很有用。

在 nginx-config 中有这样的

location / {
    rewrite ^(.*[^/])$ $1/ permanent;
    try_files $uri $uri/ /index.php?$args;
}

.htacces 需要 EQUAL 的东西。 泰。

【问题讨论】:

    标签: apache nginx rewrite


    【解决方案1】:

    它们应该非常相似。

    <IfModule mod_rewrite.c>
        RewriteEngine On
        # Your web directory root
        RewriteBase /
    
        #Make sure it's not a specific file or directory that they're trying to reach
        RewriteCond %{SCRIPT_FILENAME} !-f
        RewriteCond %{SCRIPT_FILENAME} !-d
    
        RewriteRule ^(.*[^/])$ index.php?args=$1 [NC, L]
    </IfModule>
    

    这将:

    1. 为 .htaccess 所在的文件夹标记 RewriteEngine(如果您已启用该模块);
    2. 如果文件是服务器上的目录或文件,则指定避免重定向的条件;并且
    3. 将您的正则表达式重定向到 index.php?args={所有被正则表达式捕获的内容}

    [NC, L] 标志分别告诉规则区分大小写并告诉 Apache 这是最后一个重定向规则。

    我不得不承认,我不确定您的 Regex 正在测试什么。您介意解释一下您想要实施的 URL 方案吗?我应该能够帮助您正确地制定正则表达式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      相关资源
      最近更新 更多