Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to clean urls in NGINX using framework DooPHP.

This => - http://example.com/index.php/something/more/ To This => - http://example.com/something/more/

I want to remove (clean url) the "index.php" from the url if someone try to enter in the first form. Like a permanent redirect.

How to do this config on NGINX?

Thanks.

[Update: Actual nginx config]

server {
  listen 80;
  server_name vip.example.com;
  rewrite ^/(.*) https://vip.example.com/$1 permanent;
}

server {
       listen 443;
       server_name vip.example.com;

       error_page 404 /vip.example.com/404.html;
       error_page 403 /vip.example.com/403.html;
       error_page 401 /vip.example.com/401.html;
       location /vip.example.com {
           root /sites/errors;
       }

       ssl on;
       ssl_certificate /etc/nginx/config/server.csr;
       ssl_certificate_key /etc/nginx/config/server.sky;

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

       location / {
           auth_basic  "example Team Access";
           auth_basic_user_file  config/htpasswd;
           root   /sites/vip.example.com;
           index  index.php;
       }

       location ~ \.php$ {
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /sites/vip.example.com$fastcgi_script_name;
           include        fastcgi_params;
           fastcgi_param PATH_INFO $fastcgi_script_name;
      }

}
share|improve this question

3 Answers

This was the line I was looking for, I did it my self. I could have some bugs.

What do you think?

server {

 ....

  rewrite ^/index.php/(.*) /$1  permanent;

 ....

}
share|improve this answer

I've try it on CodeIgniter 1.7 & 2.0, and i change

config.php $config['uri_protocol'] = "REQUEST_URI";

and i add try_files $uri $uri/ /index.php?r=$request_uri;

on nginx.conf, and worked

location / {
       auth_basic  "example Team Access";
       auth_basic_user_file  config/htpasswd;
       root   /sites/vip.example.com;
       index  index.php;
       try_files $uri $uri/ /index.php?r=$request_uri;
   }

maybe it same on DooPHP

share|improve this answer

If you only have php-files you can use:

location / {
    rewrite ^(.*)$ /index.php
}

location ~  \.php$ {
    fastcgi_pass    127.0.0.1:9000
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME
                    $document_root$fastcgi_script_name;
    include         fastcgi_params;
}
share|improve this answer
It hasn't worked. I have updated my nginx config file. – Gaston Mar 26 '11 at 16:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.