網元でセットアップした環境にCodeIgniterをインストールしました。
NginxのRewrite Ruleではまったので、備忘録として残しておきます。
CodeIgniter用のRewrite Rule定義を新規作成
site.com/codeigniterへのURLを書き換えます。
# CodeIgniter location /codeigniter { alias /var/www/vhosts/codeigniter; index index.php; include /etc/nginx/expires; if (!-d $request_filename) { rewrite ^/codeigniter/(.+)/$ /codeigniter/$1 permanent; } if (!-e $request_filename) { rewrite ^/codeigniter/(.*)$ /codeigniter/index.php?/$1 last; break; } } location ~ ^/codeigniter/.+.php$ { alias /var/www/vhosts/codeigniter; fastcgi_pass phpfpm; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/vhosts/codeigniter/index.php; include fastcgi_params; } location ~ /codeigniter/.ht { deny all; }
作成したファイルをinclude
# CodeIgniter include /etc/nginx/codeigniter;
CodeIgniterのURI PROTOCOLをREQUEST_URIへ変更
/* |-------------------------------------------------------------------------- | URI PROTOCOL |-------------------------------------------------------------------------- | | This item determines which server global should be used to retrieve the | URI string. The default setting of 'AUTO' works for most servers. | If your links do not seem to work, try one of the other delicious flavors: | | 'AUTO' Default - auto detects | 'PATH_INFO' Uses the PATH_INFO | 'QUERY_STRING' Uses the QUERY_STRING | 'REQUEST_URI' Uses the REQUEST_URI | 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO | */ $config['uri_protocol'] = 'REQUEST_URI';
参考情報
CodeIgniter Nginx Rewrite Rule | Libraries & Helpers
Chat with fellow EECMS users in the 'CodeIgniter Nginx Rewrite Rule' ExpressionEngine community discussion forum thread.
CodeIgniter NGINX Rewrite Rules
コメント