Discover Centmin Mod today
Register Now

Nginx Rewrite rules for Shortener site

Discussion in 'Other Web Apps usage' started by ndha, Aug 3, 2017.

  1. ndha

    ndha Member

    82
    10
    8
    Sep 28, 2014
    Ratings:
    +29
    Local Time:
    6:01 PM
    Latest
    10
    Hi all,


    i just play with shortener url site using nginx.
    But it only had .htacces rules which is i must make my own nginx rewrite for it..
    Here it is :
    Code:
    ## Admin Panel
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^admin/(.*)?$ admin/index.php?a=$1 [QSA,NC,L]
    
    ## Sitemap ###
    RewriteRule ^sitemap.xml$ sitemap.php
    
    ## Application Handler
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)?$ index.php?a=$1 [QSA,NC,L]
    
    ## Error 404 ##
    ErrorDocument 404 /index.php?a=404
    
    So i use anilcetin site to convert it (i knew it's not 100% accurate),
    here it's nginx rewrite for it :
    Code:
    rewrite ^/admin/(.*)?$ /admin/index.php?a=$1 last;
    rewrite ^/sitemap.xml$ /sitemap.php;
    rewrite ^/(.*)?$ /index.php?a=$1 last;
    error_page 404 /index.php?a=404;
    
    can someone confirm this nginx rewrite is ok ??
    or i must add something on it..
    or @eva2000 can give some lights on it..
    Thanks for any help..
     
  2. eva2000

    eva2000 Administrator Staff Member

    48,987
    11,227
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,477
    Local Time:
    9:01 PM
    Nginx 1.21.x
    MariaDB 10.x
    what is the shortener script name ? have you asked official developers for their official nginx rules or if their official documentation has ones ?
     
  3. ndha

    ndha Member

    82
    10
    8
    Sep 28, 2014
    Ratings:
    +29
    Local Time:
    6:01 PM
    Latest
    10
    it is Premium URL Shortener..
    They only had nginx rewrite for Admin page..
    Other rules must convert again..
    I think their sitemap rule still broken..
     
  4. aditbaco

    aditbaco New Member

    8
    0
    1
    Aug 29, 2021
    Ratings:
    +0
    Local Time:
    6:01 PM
    1.17.x
    10.0.x
    I'm also using this. Try this nginx config :
    Code:
    location / {
      try_files $uri $uri/ =404;
    
       if (!-e $request_filename)
        {
            rewrite ^/admin/(.*)?$ /admin/index.php?a=$1 last;
            rewrite ^/(.*)$ /index.php?a=$1 last;
            break;
        }
    
      include /usr/local/nginx/conf/503include-only.conf;
    
      }