Rewrite rules for nginx from .htaccess


#1

I’m having problems finding the right combination of rewrite rules to mimic this htaccess:

RewriteEngine On  
RewriteBase /  
RewriteRule ^index\.php$ - [L]  

# add a trailing slash to /wp-admin  
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]  

RewriteCond %{REQUEST_FILENAME} -f [OR]  
RewriteCond %{REQUEST_FILENAME} -d  
RewriteRule ^ - [L]  
RewriteRule ^(wp-(content|admin|includes).*) wp/$1 [L]  
RewriteRule ^(.*\.php)$ wp/$1 [L]  
RewriteRule . index.php [L]

I’m using Bedrock, and am trying to get a subdomain multisite installation to work with it’s /web/wp file structure. The htaccess rules that work are above, but I can’t seem to translate those into rules that work for nginx. Any help would be appreciated.


#2

This is what I've come up with so far, but it isn't working properly for files being called within wp-content, etc:

`location / { try_files $uri $uri/ /wp$uri/ /wp/index.php?q=$uri&$args; }

    location /wp {  
            index index.php;  
            try_files $uri $uri/ /wp/index.php;  
    }  

    location ~ ^/wp-content/cache/minify/(.+\.(css|js))$ {  
            try_files $uri /wp/wp-content/plugins/w3-total-cache/pub/minify.php?file=$1;  
    }  

    location ~ \.php$ {  
            try_files $uri /wp/index.php =404;  
            include fastcgi_params;  
            fastcgi_pass php;  

            fastcgi_cache_bypass $skip_cache;  
            fastcgi_no_cache $skip_cache;  

            fastcgi_cache WORDPRESS;  
    }`  

#3

I am sorry to say, but I am not familiar with bedrock's structure.

As a general tip, you can use try_files with location /wp-content and location / separately.


#4

From what I understand, it's essentially the same as WP Skeleton. I've tried almost every conceivable combination, but I just can't come up with rules that will work with it with a subdomain multisite installation.


#5

We may be able to look into bedrock once we starts working on https://github.com/rtCamp/easyengine/issues?milestone=8&state=open


#6
rewrite ^/(wp-.*.php)$ /wp/$1 last;  
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;  

#7