WordPress as a subdirectory
September 21, 2010 09:54AM
Hello all

I'm having a problem setting up a PHP framework with a Wordpress installation as a subdirectory.

The set up:

example.com/blog needs to be handled by Wordpress
exmple.com/* everything else needs top be re-written to the index.php file of the framework

The framework works perfectly, even serving static files (images) from a subdirectory, but WP is returning a 404 when it goes to the installation step (/blog/wp-admin/install.php).

The current semi-working config is:
server {
server_name www.example.com;
rewrite ^(.*) http://example.com$1 permanent;

server {
listen 80;
server_name example.com;
access_log /var/log/nginx/example.com.access.log;

location /blog {
set $php_root /var/www/example.com/public/blog;
try_files $uri $uri/ /index.php?q=$uri&$args;

location /socializer {
set $php_root /var/www/example.com/public/socializer;
try_files $uri $uri/ /index.php?q=$uri&$args;

location / {
set $php_root /var/www/example.com/public;
try_files $uri $uri/ /index.php?q=$uri&$args;

## Images and static content is treated differently
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
access_log off;
expires 30d;
root /var/www/example.com/public/;

## Parse all .php file in the directory
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_pass backend;

## Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
upstream backend {

What's going on? How can I setup nginx to rewrite the blog directory to WP and everything else to the framework?

Re: WordPress as a subdirectory
November 12, 2010 03:15PM
WordPress rewrite for a subdirectory:
location /subdirectory {
try_files $uri $uri/ /subdirectory/index.php?q=$uri&$args;
Re: WordPress as a subdirectory
October 11, 2013 05:35AM

I have the same problem with another one trouble: magento.

Did you solve it?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 129
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready