From apache to nginx: wordpress rewrite rule

28,867

You should read http://wiki.nginx.org/WordPress

e.g.

    location /blog {
            try_files $uri $uri/ /blog/index.php?$args;
    }

    location ~ \.php$ {
            fastcgi_split_path_info ^(/blog)(/.*)$;
    }
Share:
28,867
gaggina
Author by

gaggina

Updated on March 23, 2020

Comments

  • gaggina
    gaggina about 4 years

    I'm migrating from apache2 to nginx. I cant figure out how to to rewrite this rewrite rules for wordpress.

    This is actually my configuration file

    server {
            listen 80;    
            root /usr/share/nginx/blog.com/public_html;
            index index.html index.htm index.php;
    
            server_name blog.com www.blog.com;
    
            location / {
                    try_files $uri $uri/ /index.html;
    
            }
    
            location /doc/ {
                    alias /usr/share/doc/;
                    autoindex on;
                    allow 127.0.0.1;
                    allow ::1;
                    deny all;
            }
    
            location ~ .php$ {
                    fastcgi_pass 127.0.0.1:9000;
    
                    fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/blog.com/public_html$fastcgi_script_name;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
    
    }
    

    I'm using php5-fpm.

    And this is the rule I would like to add :

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    
    # END WordPress
    

    Can you please help me? Thanks :)