Single WordPress With SubDirectory
set $dir "";
if ($request_uri ~ ^/([^/]*)/.*$ ) {
set $dir1 /$1;
}
location / {
try_files $uri $uri/ $dir1/index.php?$args;
}
I have looked EVERYWHERE for an nginx config that could accomplish this. I just tested this and it works!
Thank you!
Glad to know that it worked for you!
Welcome :)
@RakshitThakker this issue will be complete when we will have subdir-wordpress site creation in easyeninge
Sexy.
I am a little confused as this is my first experience with nginx and regular expressions. Is this the full set of directives needed in the "default" configuration file? Or is this to go inside the default server block configurations that ship with nginx installation? Your help is much appreciated.
@raytara
This configuration can go inside /etc/nginx/sites-available/example.com
Sample example.com: https://github.com/rtCamp/easyengine/blob/master/usr/share/easyengine/nginx/wp/basic.conf
@MiteshShah I am is new at server world including nginx.
I am confused, how to use this code. Iam installing easy engine+wp+wpsc that is very easy to use and relly help me.
but I have wordpress on subdirectory so I found this topic, but I don't know how to add this code. Can you please post here complete example code placement for this config?
please edit this config files to add code above,
https://github.com/rtCamp/easyengine/blob/master/usr/share/easyengine/nginx/wp/basic.conf
Many thanks before
@thenoobi I'm assume you are using single wordpress with nginx fastcgi cahe (--wpfc)
In this case you need to edit example.com
ee site edit example.com
Find the following line
root /var/www/example.com/htdocs;
index index.php index.htm index.html;
Add following codes below that line
set $dir "";
if ($request_uri ~ ^/([^/]*)/.*$ ) {
set $dir1 /$1;
}
Now find the location block
location / {
try_files $uri $uri/ /index.php?$args;
}
Chnage it
location / {
try_files $uri $uri/ $dir1/index.php?$args;
}
NOTE: I'm not tested this code with --wpfc option you need to test yourself
@MiteshShah Many thanks for your instructions,
I have succesfully install wp on sub and I can access that page.
But I have another problem. custom permalink is not working now.
I am using permalinks:
/%category%/post-name.html
I get 404 when using this.
Try switch back to default permalink and working. Here my .htaccess setting:
RewriteCond %{REQUEST_URI} !^.[^/]$ RewriteCond %{REQUEST_URI} !^.//.$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.=.* RewriteCond %{HTTP:Cookie} !^.(comment_author|wordpress_logged_in|wp-postpass_)._$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{HTTPS} !on RewriteCond %{DOCUMENT_ROOT}/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html.gz -f RewriteRule ^(.*) "/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html.gz" [L]
RewriteCond %{REQUEST_URI} !^.[^/]$ RewriteCond %{REQUEST_URI} !^.//.$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.=.* RewriteCond %{HTTP:Cookie} !^.(comment_author|wordpress_logged_in|wp-postpass_)._$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTPS} on RewriteCond %{DOCUMENT_ROOT}/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index-https.html -f RewriteRule ^(.*) "/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index-https.html" [L]
RewriteCond %{REQUEST_URI} !^.[^/]$ RewriteCond %{REQUEST_URI} !^.//.$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.=.* RewriteCond %{HTTP:Cookie} !^.(comment_author|wordpress_logged_in|wp-postpass_)._$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTPS} !on RewriteCond %{DOCUMENT_ROOT}/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html -f RewriteRule ^(.*) "/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html" [L]
NOTE: Main sites is using easy engine wordpress wpsc and running fine with all permalinks
Any missing confiig in htaccess?
@thenoobi .htaccess not work with nginx You need to write custom rules for nginx
@MiteshShah Thanks for your answer And what should I do now :(
@thenoobi
I think you are using wrong permalink structure. The correct one is
/%category%/%postname%.html
@nitun
yes sorry wrong type here but in wp permalinks config is still /%category%/%postname%.html
:)
@MiteshShah I am try to conver my .htaccess to nginx config using this tools http://winginx.com/en/htaccess
but I just redirected to main domain
Im trying to access domain.com/sub/catname/postname.html and get redirected to domain.com/catname/postname.html
@thenoobi First clean your nginx fastcgi cache then test
rm -rf /var/run/nginx-cache/*
Finally I'm reintalling easy engine with ee site create example.com --wpsubdom --wpfc and follow your guide, everything is working great, Many thanks for your support.
Here the right step:
- After install ee system, instal wp with fast cgi: ee site create example.com --wpsubdir --wpfc
- Add this code to server block
set $dir ""; if ($request_uri ~ ^/([^/])/.$ ) { set $dir1 /$1; } location / { try_files $uri $uri/ $dir1/index.php?$args; }
- rm -rf /var/run/nginx-cache/*
- restart nginx
- Finish
And now I have question, how about cache for WP sub directory? can I use wpfc like main site?
LOL,
After my step above, example.com/wpsubdir is running great with custom permalinks, but example.com is get 404 when use /%category%/%postname%.html
@thenoobi first this issue is for only single wordpress not for multisite.
Also in my above comment i'm said
I'm assume you are using single wordpress with nginx fastcgi cahe (--wpfc)
After above changes site work on subdirectory but ee site list show site install on root ee site create domain.com -- still state site already exist. Meaning I cannot install another site again? Did something wrong? Tq
@dettlee
ee site list is only show sites which is found on /etc/nginx/sites-enabled
Also you added custom rules on example.com to make sub-directory working so ee site list not aware of this and this feature is not implemented in easyengine yet.
ee site create domain.com -- still state site already exist.
If site already exist then you can't create site you have to delete this site first or choose another domain like
ee site create hello.com
totally aware of the subdirectory is not supported yet... just my worth of 2cents comment, when creating in subdirectory it should allow to create another subdirectory under other name tq for the good work