Join the community today
Become a Member

Wordpress rewrite from .html to without

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

  1. Mak Adang

    Mak Adang Member

    39
    13
    8
    Jan 4, 2015
    Ratings:
    +14
    Local Time:
    2:12 AM
    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

    30,168
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,137
    Local Time:
    5:12 AM
    Nginx 1.13.x
    MariaDB 5.5
    Last edited: Dec 17, 2016
    • Like Like x 1
  3. Mak Adang

    Mak Adang Member

    39
    13
    8
    Jan 4, 2015
    Ratings:
    +14
    Local Time:
    2:12 AM
    1.9.0
    10.0.18-MariaDB
  4. Mak Adang

    Mak Adang Member

    39
    13
    8
    Jan 4, 2015
    Ratings:
    +14
    Local Time:
    2:12 AM
    1.9.0
    10.0.18-MariaDB
  5. eva2000

    eva2000 Administrator Staff Member

    30,168
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,137
    Local Time:
    5:12 AM
    Nginx 1.13.x
    MariaDB 5.5
    what happens ? errors ? symptoms ? where did you place it ? contents of your nginx vhost domain.com.conf ?
     
  6. Mak Adang

    Mak Adang Member

    39
    13
    8
    Jan 4, 2015
    Ratings:
    +14
    Local Time:
    2:12 AM
    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

    30,168
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,137
    Local Time:
    5:12 AM
    Nginx 1.13.x
    MariaDB 5.5
    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

    39
    13
    8
    Jan 4, 2015
    Ratings:
    +14
    Local Time:
    2:12 AM
    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

    30,168
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,137
    Local Time:
    5:12 AM
    Nginx 1.13.x
    MariaDB 5.5
    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
     
    • Like Like x 1
  10. Mak Adang

    Mak Adang Member

    39
    13
    8
    Jan 4, 2015
    Ratings:
    +14
    Local Time:
    2:12 AM
    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

    224
    59
    28
    Dec 4, 2016
    The Canadas
    Ratings:
    +112
    Local Time:
    9:12 PM
    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
     
    • Like Like x 1