Rewrite rules for "random" subfolders


I would like to migrate my page from a webhoster to my own vServer
Nginx. So far I got everything up and running EXCEPT these stupid
file. Let me explain:

My site contains several galleries with slideshows. When you are
one of those you click a link which looks like this


(only DOMAIN/galleries and -single.php) are fixed. The rest can vary.
links are generated by Lightroom and a plugin and during this process a
.htaccess file will be copied into each folder. The content looks like

RewriteEngine On RewriteRule ^(.*)-single.*php$ single.php?id=$1 [L]

This makes my link
point to this

as you can see, the “DSC01154” will be passed through. I am trying for
several days to create a rewrite rule for Nginx doing the same without
killing my page.

Does anyone knows a solution for this?

Posted at Nginx Forum:


Does this work?
rewrite ^(.)/(.)-single.php $1/single. php?id=$2 last;

Not tested, so anything could happen.

Unfortunately not -.- here is a small summary of my vhost

server {

    location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ @rewrites;
            rewrite ^(.*)/(.*)-single\.php $1/single.php?id=$2 last;

    location @rewrites {
            rewrite ^ /index.php last;


I emptied my cache and restarted nginx as well … no success

ryd994 Wrote:

RewriteEngine On
several days to create a rewrite rule for Nginx doing the same
[email protected]
nginx Info Page

nginx mailing list
[email protected]
nginx Info Page

Posted at Nginx Forum:

Try the below one in the server context …outside all location blocks.
can enable dedug log and do rewrite_log on; to see if its matching etc.
Good Luck!

rewrite ^/galleries/album-set/album-2/(.*)-single.php
/galleries/album-set/album-2/single.php?id=$1 last;

Great! It is working now, thank you very much :slight_smile:

Posted at Nginx Forum: