Support » Networking WordPress » permalink problem on nginx

  • I read Codex > Nginx and succeeded to have network install (subdirectory).

    But I have two problems with permalink settings ( ).

    First, I see a slug /blog before input area.
    Second, there is a slug /index.php/ in the input area.

    Please see screenshot.

    I can’t get rid of either of them.
    (/blog is uneditable, and /index.php/ appears every time even I submit without /index.php/…:( )

    I have these problems only at the main (blog id = 1) site.

    Please if you know how to fix it, please let me know.

    Here is my nginx config files.


    user              nginx;
    worker_processes  2;
    error_log  /var/log/nginx/error.log;
    pid        /var/run/;
    events {
        worker_connections  1024;
    http {
    	include	/etc/nginx/mime.types;
    	default_type 	application/octet-stream;
    	access_log	/var/log/nginx/access.log;
    	sendfile        on;
    	#tcp_nopush     on;
    	keepalive_timeout  3;
    	#tcp_nodelay	on;
    	gzip  on;
    	#client_max_body_size 13m;
    	index      index.php index.html index.htm;
    	log_not_found off;
    #	Upstream to abstract backend connection(s) for PHP.
    #	upstream php {
    #		server unix:/tmp/php-fpm.sock;
    #		server;
    #	}
    	include		sites-enabled/*;
    	server {
    	listen       80;
    	root /var/www/vhosts/;
    	if ($http_host != "") {
    		rewrite ^$request_uri permanent;
    	include global/restrictions.conf;
    	include global/wordpress-ms-subdir.conf;
    	access_log /var/log/nginx/;
    	}# end server{}
    }# end http {}


    # This order might seem weird - this is attempted to match last if rules below fail.
    location / {
    	try_files $uri $uri/ /index.php?$args;
    ##necessary if using a multi-site plugin
    server_name_in_redirect off;
    ##necessary if running Nginx behind a reverse-proxy
    #port_in_redirect off;
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    # Directives to send expires headers and turn off 404 error logging.
    location ~ .*\.(txt|xml|html?|jpe?g|JPE?G|gif|GIF|png|PNG|swf|SWF|wmv|WMV|flv|FLV|css|CSS|js|JS|inc|ico|gz) {
    	expires 24h;
    	log_not_found off;
    # Pass uploaded files to wp-includes/ms-files.php.
    rewrite /files/$ /index.php last;
    # For multisite:  Use a caching plugin that creates symlinks to the correct subdirectory structure to get some performance gains.
    set $cachetest "$document_root/wp-content/cache/ms-filemap/${host}${uri}";
    if ($uri ~ /$) {
    	set $cachetest "";
    if (-f $cachetest) {
    	# Rewrites the URI and stops rewrite processing so it doesn't start over and attempt to pass it to the next rule.
    	rewrite ^ /wp-content/cache/ms-filemap/${host}${uri} break;
    if ($uri !~ wp-content/plugins) {
    	rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
    # Uncomment one of the lines below for the appropriate caching plugin (if used).
    #include global/wordpress-ms-subdir-wp-super-cache.conf;
    #include global/wordpress-ms-subdir-w3-total-cache.conf;
    # Rewrite multisite '.../wp-.*' and '.../*.php'.
    if (!-e $request_filename) {
    	rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    	rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
    	rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
    	rewrite ^.*$ /index.php last;
    # Pass all .php files onto a php-fpm/php-fcgi server.
    location ~ \.php$ {
    	root 			html;
    	fastcgi_index	index.php;
    	fastcgi_param	SCRIPT_FILENAME /var/www/vhosts/$fastcgi_script_name;
    	include			fastcgi_params;


Viewing 15 replies - 1 through 15 (of 16 total)
  • I reinstalled now subdomain with same code I wrote.

    And it worked very well.

    I didn’t get any /blog/ slug before input area or /index.php/ slug in ther input area..

    Is there anyone who has the same problem with me??


    I still don’t know how to fix it…

    Here are the wrong urls and how I want to fix.

    Wrong sample page url:
    I want:

    Wrong category page url:
    It should be:

    Wrong first post page url:
    It should be:

    The front page is displayed as which is ok.

    I can’t get rid of index.php/ at “Permalink Setting” page. index.php/ appears always even I submit without this slug…

    I fixed it.
    … not really but almost..

    I don’t get any /blog slug any more.

    I still get /index.php slug but I do as follows

    1. Define my permalink customize when it’s single install.

    2. Never touch permalink submit after multi-sited.

    3. You can change permalink structure if you define( ‘MULTISITE’, false );.

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    First, I see a slug /blog before input area.

    Rolling back to that… I was avoiding this thread b/c I don’t know nginx well, but I DO know WordPress, and the blog slug is hard coded in if you’re using subfolder installs. You shouldn’t change that.

    Thank you for the reply!
    I’m glad to know someone cared about my thread 🙂

    Now I don’t have the /blog slug.
    I customize my permalink as single-installed wp user, which is realized by changin define( ‘MULTISITE’, false ); at wp-config.php, and then come back to multi-sited wp.

    Is this going to cause any trouble to my site?

    I guess /blog slug is required to distinguish the main site from other child blogs..
    Is it something about performance?

    The main site doesn’t have /blog slug when it’s multi-sited.

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    I guess /blog slug is required to distinguish the main site from other child blogs..
    Is it something about performance?

    Yes and yes. The main site will have /blog slug ONLY if you’re using subfolders (subdomains don’t have it).

    Thank you Ipstenu!

    Is there any problem to leave the setting as it is?
    I mean that I don’t insert /blog slug (it’s possible to set permalink setting as single wp user and then get multi-sited).

    If it is possible to cause a serious trouble, can I change /blog to something else like /home or /main?

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    It can cause problems with any blogs named ‘blog’, but if you make sure not to do THAT, you’re okay.

    You can’t (currently) rename it. it’s actually hard coded into the permalink page. If you save permalinks, it SHOULD force it back it (it does on .htaccess/apache sites, dunno if nginx makes it different).


    I guess /blog slug is not able to be used as new child blog slug for it’s listed as unavailable in the network setting page.
    And maybe I shouldn’t /blog as category/tag slugs..:|

    And ofcourse I’ll avoid clicking submit button at permalink setting page:)

    Thanks, Ipstenu!
    Now my questions are all resolved!
    I hope this thread will be good for the wp community too!

    How did you fixed the issue? I saw you post your config and then it doesn’t work and then it worked. What did you do? I’m running nginx 0.8.54 and WP 3.2.1 (not multisite). If I changed the PERMALINKS from “Default” to “Day and name” all my links are broken and so does some plugins.

    Is it as simple as having the rewrite rule below in nginx.conf?

    if ($http_host != "") {
    		rewrite ^$request_uri permanent;

    Discovered another post, the below links help:

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    That plugin doesn’t work with 3.2 last I checked.



    Add this to functions.php

    add_filter( 'got_rewrite', '__return_true', 999 );

    WordPress is checking if mod_rewrite is enabled (which of course it’s not since we aren’t using Apache), so force this to return true and it won’t add the additional index.php into the permalinks.

    Then, just save your permalinks again and you should be good to go.


    Use Nginx Compatibility by Vladimir Kolesnikov to setup your permalinks running on nginx (it does basically the same thing as defunctlife wrote above + more)

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘permalink problem on nginx’ is closed to new replies.