atom feed29 messages in ru.sysoev.nginxRe: Rewrite help when files do NOT ha...
FromSent OnAttachments
pk899Jun 1, 2011 5:00 am 
António P. P. AlmeidaJun 1, 2011 6:05 am 
pk899Jun 1, 2011 6:22 am 
António P. P. AlmeidaJun 1, 2011 6:30 am 
Edho P AriefJun 1, 2011 6:32 am 
pk899Jun 1, 2011 7:02 am 
António P. P. AlmeidaJun 1, 2011 7:23 am 
pk899Jun 1, 2011 7:31 am 
António P. P. AlmeidaJun 1, 2011 7:53 am 
pk899Jun 1, 2011 8:29 am 
António P. P. AlmeidaJun 1, 2011 8:42 am 
pk899Jun 2, 2011 3:10 am 
António P. P. AlmeidaJun 2, 2011 11:53 am 
Marcos OrtizJun 2, 2011 12:27 pm 
Alexandr GomoliakoJun 2, 2011 1:12 pm 
Marcos Ortiz ValmasedaJun 2, 2011 1:17 pm 
pk899Jun 2, 2011 4:33 pm 
António P. P. AlmeidaJun 2, 2011 5:40 pm 
pk899Jun 2, 2011 6:21 pm 
António P. P. AlmeidaJun 2, 2011 6:44 pm 
pk899Jun 2, 2011 7:08 pm 
António P. P. AlmeidaJun 2, 2011 7:19 pm 
Antoine BonavitaJun 3, 2011 1:33 am 
pk899Jun 3, 2011 11:37 am 
pk899Jun 3, 2011 11:40 am 
António P. P. AlmeidaJun 3, 2011 11:46 am 
pk899Jun 3, 2011 9:26 pm 
António P. P. AlmeidaJun 4, 2011 9:08 am 
pk899Jun 4, 2011 10:51 pm 
Subject:Re: Rewrite help when files do NOT have a ".php" extension
From:António P. P. Almeida (ap@perusio.net)
Date:Jun 1, 2011 6:05:57 am
List:ru.sysoev.nginx

On 1 Jun 2011 13h00 WEST, ngin@nginx.us wrote:

Loving Nginx so far! So much faster and leaner than Apache.

Apologies for this yet another Rewrite rule help after so many threads, but one of domains has a special need and I am struggling with Rewrite rules.

The logic is simple:

1. For anything in /site folder, it should treat the static files as it is, but all else is php (file names don't have .php extension). Still further in this folder:

a. Within /site/private, it should be password protected b. Within /site/wordpress, there is a wordpress blog

2. For the main folder "/" all URLs should be directed to "/site/redirect".

Following is in URI examples, so that it easier to visualize:

(Lines starting with asterisks ** are already working)...

/abc ---> /site/redirect?u=abc /xyz ---> /site/redirect?u=xyz

** /site/abc ---> /site/abc (as PHP file) ** /site/xyz ---> /site/xyz (as PHP file)

** /site/1.gif ---> Served as it is, static ** /site/2.png ---> Served as it is, static

** /site/private/abc ---> Inside http auth, serve as PHP /site/private/ ---> Inside http auth, serve as PHP /site/private/index

/site/wordpress/.. ---> This is the usual wordpress thing.. The apache rules used to be: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /site/wordpress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /site/wordpress/index.php [L] </IfModule>

location / { rewrite ^/(.*)$ /site/redirect?u=$1; }

location /site { location
/site/.*\.(?:xml|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|doc|xls|exe|ppt)$ expires max; access_log off; log_not_found off;

} location /site/private { auth_basic "Restricted"; auth_basic_user_file
/home/MYDOMAIN/.htpasswds/public_html/site/private/passwd; <fastcgi block here> }

location /site/wordpress { ## Regular PHP processing. location ~ ^/site/wordpress/(?<script>.+\.php)(?<path_info>.*)$ { include fastcgi.conf; ## The fastcgi_params must be redefined from the ones ## given in fastcgi.conf. No longer standard names ## but arbitrary: named patterns in regex. fastcgi_param SCRIPT_FILENAME $document_root$script; fastcgi_param SCRIPT_NAME $script; fastcgi_param PATH_INFO $path_info; ## Passing the request upstream to the FastCGI ## listener. fastcgi_pass unix:/dev/shm/php5-fpm.MYDOMAIN.sock;; } } }

location /site/redirect { <fastcgi block here> }

## you need a try_files directive here but your "desired" config is ## quite confusing and I don't know what you need/want. Perhaps:

try_files $uri $uri/ /site/wordpress; ## ??? }

For the fastcgi block use nested locations and named captures like the above example, always prefixing the regex with the outer location string, like in the /site/wordpress location.

--- appa