only removing index.php rule works on my NginX and CodeIgniter as rewrite. Why?
Posted
by
Atomei Cosmin
on Server Fault
See other posts from Server Fault
or by Atomei Cosmin
Published on 2012-09-07T01:30:33Z
Indexed on
2012/09/07
3:39 UTC
Read the original article
Hit count: 235
I am very new in rewriting in nginx but although I've spent 2 days reading on forums, I still can't get some Codeigniter rewrites working ...
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 settings are: well for uri_protocol: REQUEST_URI;
What i noticed is that from this rule: rewrite ^/(.)$ /index.php?/$1; it works ever if i write it like this: rewrite ^/(.)$ /index.php?; It might be a wild guess but it stops at the question mark... Anyhow what I need are rules as these from .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]
Can anyone tell me what i'm doing wrong and show me a proper way for at least one rule? It would be more than helpful. Thank you in advance! ^^
PS: I made it work on apache by using Path_info for uri_protocol.. if this info is of any help, and i remember having kind of the same problem there too but switching to path_info made it all good.
© Server Fault or respective owner