Learn about Centmin Mod LEMP Stack today
Register Now

Wordpress rewrite from .html to without

Discussion in 'Blogs & CMS usage' started by Mak Adang, Dec 16, 2016.

  1. Mak Adang

    Mak Adang Member

    62
    20
    8
    Jan 4, 2015
    Ratings:
    +23
    Local Time:
    12:43 PM
    1.9.0
    10.0.18-MariaDB
    Hi @eva2000 if I using permalink with .html before, is there any config to redirect .html permalink to /%postname%/ so I`m not get 404.

     
  2. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    3:43 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Last edited: Dec 17, 2016
  3. Mak Adang

    Mak Adang Member

    62
    20
    8
    Jan 4, 2015
    Ratings:
    +23
    Local Time:
    12:43 PM
    1.9.0
    10.0.18-MariaDB
  4. Mak Adang

    Mak Adang Member

    62
    20
    8
    Jan 4, 2015
    Ratings:
    +23
    Local Time:
    12:43 PM
    1.9.0
    10.0.18-MariaDB
  5. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    3:43 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    what happens ? errors ? symptoms ? where did you place it ? contents of your nginx vhost domain.com.conf ?
     
  6. Mak Adang

    Mak Adang Member

    62
    20
    8
    Jan 4, 2015
    Ratings:
    +23
    Local Time:
    12:43 PM
    1.9.0
    10.0.18-MariaDB
    I put the code in vhost domain.conf after server_name domain.com
    after save the code - restart with error on nginx config. please advise @eva2000
     
  7. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    3:43 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    When you create a new nginx vhost domain via centmin.sh menu option 2 or menu option 22 or via /usr/bin/nv cli command line, you will create the Nginx vhost files and directories. You will get an outputted the path location where it will create the domain name's vhost conf file named newdomain.com.conf (and newdomain.com.ssl.conf if you selected yes to self signed SSL)
    • Nginx vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.conf
    • Nginx HTTP/2 SSL vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
    • Nginx Self-Signed SSL Certificate Directory at /usr/local/nginx/conf/ssl/newdomain.com
    • Vhost public web root will be at /home/nginx/domains/newdomain.com/public
    • Vhost log directory will be at /home/nginx/domains/newdomain.com/log
    Please post the contents of /usr/local/nginx/conf/conf.d/newdomain.com.conf and if applicable /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf wrapped in CODE tags (outlined at How to use forum BBCODE code tags)
     
  8. Mak Adang

    Mak Adang Member

    62
    20
    8
    Jan 4, 2015
    Ratings:
    +23
    Local Time:
    12:43 PM
    1.9.0
    10.0.18-MariaDB
    Dear @eva2000 this is my vhost domain.conf
    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #            listen   80;
    #            server_name domain.com;
    #            return 301 $scheme://www.domain.com$request_uri;
    #       }
    
    server {
    
      server_name domain.com www.domain.com;
      rewrite ^/([^/]+)\.html$ /$1
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Frame-Options SAMEORIGIN;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.com/log/access.log main_ext buffer=256k flush=60m;
      error_log /home/nginx/domains/domain.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf;
      root /home/nginx/domains/domain.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
    "domain.com.conf" 92L, 3419C
    # server and/or vhost site
      #include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      include /usr/local/nginx/conf/wpincludes/domain.com/wpcacheenabler_domain.com.conf;
      #include /usr/local/nginx/conf/wpincludes/domain.com/wpsupercache_domain.com.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/wpincludes/domain.com/rediscache_domain.com.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      #try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # for wp cache enabler plugin
      try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      #try_files $uri $uri/ /index.php?$args;
    
      }
    
    location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=1 nodelay;
        #limit_conn xwpconlimit 30;
     #auth_basic "Private";
        #auth_basic_user_file /home/nginx/domains/domain.com/htpasswd_wplogin;
        include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /(xmlrpc\.php) {
        limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
        # https://community.centminmod.com/posts/18828/
        #include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
      include /usr/local/nginx/conf/wpincludes/domain.com/wpsecure_domain.com.conf;
      include /usr/local/nginx/conf/php-wpsc.conf;
      # https://community.centminmod.com/posts/18828/
      #include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    And for ssl I`m not used them when install.

    Thanks @eva2000
     
  9. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    3:43 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    rewrite goes within your location / {} context and rewrite missing ending semi-colon ;
    Code (Text):
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
      rewrite ^/([^/]+)\.html$ /$1;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      #try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # for wp cache enabler plugin
      try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      #try_files $uri $uri/ /index.php?$args;
    
      }

    you also have "domain.com.conf" 92L, 3419C in vhost probably from copy and paste in linux text editor ?

    you should use cat instead to get output of file contents
    Code (Text):
    cat /usr/local/nginx/conf/conf.d/newdomain.com.conf
     
  10. Mak Adang

    Mak Adang Member

    62
    20
    8
    Jan 4, 2015
    Ratings:
    +23
    Local Time:
    12:43 PM
    1.9.0
    10.0.18-MariaDB
    Thanks @eva2000 for your correction.
    Nginx now running normally but if I try redirect .html in browser still show 404 page not found.
     
  11. SFLC

    SFLC Active Member

    223
    59
    28
    Dec 4, 2016
    The Canadas
    Ratings:
    +112
    Local Time:
    7:43 AM
    1
    10
    just an fyi, its good practice to run

    nginx -t

    after any changes to nginx conf files, gives u some heads up if things may fail on the restart and clues on what any issues are

    also did you clear your cache from wordpress if your running that plugin