Rewrite help when files do NOT have a ".php" extension

António P. P. Almeida appa at perusio.net
Wed Jun 1 18:24:15 MSD 2011


On 1 Jun 2011 15h03 WEST, nginx-forum at nginx.us wrote:

> Sorry edogawan. That was funny :) 
>
> Appa, yes I agree, it is much clearer with the blocks now making
> sense.
>
>
> NOT working though. I will deal with Wordpress etc later. Want my
> root folder stuff to work first. Here are my simple rules.
>
>
> #----------------
> location / {
> rewrite   ^/([-~a-zA-Z0-9_\.]+)$        /site/get?u=$1; 
> }  
>
> location /site {
>
> location /site/get {
> fastcgi_pass    unix:/dev/shm/php5-fpm.MYDOMAIN.sock;
> include         fastcgi_params;
> fastcgi_param   SCRIPT_FILENAME  
> $document_root$fastcgi_script_name;
> fastcgi_param   PATH_TRANSLATED  
> $document_root$fastcgi_script_name;
> fastcgi_param   SCRIPT_NAME       $fastcgi_script_name;
> }
>
> try_files $uri $uri/ /site/get?u=$uri  =404; 
>
> }  # END OF SITE BLOCK
> #----------------


This won't work unless you have defined the name of the script that is
to be executed by the upstream fastcgi process.

What is the name of the script that receives the u argument? get.php? index.php?


> Questions: 
>
> (1) What am I missing here? The "fastcgi_params" is a file that has
>     the
> usual bits and pieces. 

Yes.

> (2) Will a more precise regexp like above be faster, or should i
>     leave
> it as "(.*)"? 

I don't think it will make much of a difference. But I'm not privy to
the details of libpcre implementation. Perhaps Igor or Maxim can shed
more light on that.

Of course the more specific you are the better it is in a security
sense at least, IMHO.

--- appa



More information about the nginx mailing list