仅删除 index.php 规则在我的 NginX 和 CodeIgniter 上作为重写有效。为什么?

仅删除 index.php 规则在我的 NginX 和 CodeIgniter 上作为重写有效。为什么?

尽管我花了两天时间阅读论坛,但我仍然无法让一些 Codeigniter 重写在 Nginx 中工作。以下是服务器配置:

server {
    listen *:80;

    server_name artademy.com www.artademy.com;
    root   /var/www/artademy.com/web;
    index index.html index.htm index.php index.cgi index.pl index.xhtml;

    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1;
    }

    if (!-e $request_filename)
    {
        rewrite ^/(index.php\?)/(.*)$ /$1/mobile_app last;
        break;
    }

    error_log /var/log/ispconfig/httpd/artademy.com/error.log;
    access_log /var/log/ispconfig/httpd/artademy.com/access.log combined;

    ## Disable .htaccess and other hidden files
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    } 

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location /stats {
        index index.html index.php;
        auth_basic "Members Only";
        auth_basic_user_file /var/www/clients/client0/web3/.htpasswd_stats;
    }

    location ^~ /awstats-icon {
                     alias /usr/share/awstats/icon;
     }

    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9012;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_intercept_errors on;
    }
 }

Codeigniter 的设置是:uri_protocol 是:REQUEST_URI;

我注意到,从这个规则来看:rewrite ^/(.*)$ /index.php?/$1;它是有效的,但如果我这样写:rewrite ^/(.*)$ /index.php?;。这可能是一个大胆的猜测,但它会在问号处停止。

无论如何,我需要的是如下规则.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ 
RewriteRule    ^([a-z]{2})$   index.php?/home_page?lang=$1 [L,QSA]
RewriteRule    ^([a-z]{2})$   index.php?/home_page?lang=$1 [L,QSA]

#how_it_works
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^how-it-works/(en)$   index.php?/how_it_works?lang=en [L,QSA]

#order_status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^order-status/(en)$   index.php?/order_status?lang=en [L,QSA]

有人能告诉我我做错了什么,并向我展示至少一条规则的正确方法吗?这非常有帮助。提前谢谢您!^^

PS:我通过使用 uri_protocol 的 Path_info 使其在 apache 上工作。如果此信息有帮助的话。我记得那里也遇到过类似的问题,但切换到 path_info 就好了。

PS.2:我确信我的 .htaccess 运行正常。例如,我想将 artademy.com/how-it-worksES/es 重写为 arademy.com/index.php?/how_it_works?lang=es

相关内容