Skip to content

Instantly share code, notes, and snippets.

@almays
Created October 21, 2012 21:55
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save almays/3928668 to your computer and use it in GitHub Desktop.
Save almays/3928668 to your computer and use it in GitHub Desktop.
Unix conf: Sendy nginx rewrite rules
index index.php index.html;
root /your/path/to/the/sendy;
location = / {
index index.php;
}
location / {
if (!-f $request_filename){
rewrite ^/([a-zA-Z0-9-]+)$ /$1.php last;
}
}
location /l/ {
rewrite ^/l/([a-zA-Z0-9/]+)$ /l.php?i=$1 last;
}
location /t/ {
rewrite ^/t/([a-zA-Z0-9/]+)$ /t.php?i=$1 last;
}
location /w/ {
rewrite ^/w/([a-zA-Z0-9/]+)$ /w.php?i=$1 last;
}
location /unsubscribe/ {
rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last;
}
location /subscribe/ {
rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 last;
}
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location ~ \.php {
fastcgi_index index.php;
include fastcgi_params;
keepalive_timeout 0;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
@gnif
Copy link

gnif commented Feb 8, 2016

You could simplify this greatly with just this single clause:

location ~ ^/(?<dir>[a-zA-Z0-9]+)(/|$) {
        try_files $uri $uri/ /$dir.php?$args;
}
try_files $uri $uri/ /index.php?$args;

@jamesw
Copy link

jamesw commented Jun 9, 2016

You could simplify this greatly with just this single clause:


location ~ ^/(?<dir>[a-zA-Z0-9]+)(/|$) {
        try_files $uri $uri/ /$dir.php?$args;
}
try_files $uri $uri/ /index.php?$args;

Seriously that does not work.
Follow the gistfile1.txt instructions above and all should be good, thanks for sharing, been tearing my hair out for hours on this

@luisdalmolin
Copy link

Worked for me. Thanks.

@fabianus76
Copy link

Thanks for this !
I just had to change

fastcgi_pass 127.0.0.1:9000;

to

fastcgi_pass fastcgi_backend;

and it worked for me!

@bh8ur8js
Copy link

bh8ur8js commented Mar 7, 2019

Hi, Im sorry, is SCRIPT_FILENAME in the above a place holder or the value required? sorry by I too have been going nuts on this.

If any one can help I would bee very grateful..

info.php doest work either.

''
server {
listen 80;
index index.php index.html;
root /var/www/sendy.ukcil.com/html/;

location = / {
index index.php;
}

location / {
if (!-f $request_filename){
rewrite ^/([a-zA-Z0-9-]+)$ /$1.php last;
}
}

location /l/ {
rewrite ^/l/([a-zA-Z0-9/]+)$ /l.php?i=$1 last;
}

location /t/ {
rewrite ^/t/([a-zA-Z0-9/]+)$ /t.php?i=$1 last;
}

location /w/ {
rewrite ^/w/([a-zA-Z0-9/]+)$ /w.php?i=$1 last;
}

location /unsubscribe/ {
rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last;
}

location /subscribe/ {
rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 last;
}

location ~* .(ico|css|js|gif|jpe?g|png)(?[0-9]+)?$ {
expires max;
log_not_found off;
}

location ~ .php {

    fastcgi_index index.php;
    include fastcgi_params;
    keepalive_timeout 0;
    fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     fastcgi_pass    127.0.0.1:9000;

}
''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment