Nginx Rewrite and Redirect?

I have an arcade gaming site. I want to convert my urls to sef.

category : domain.com/index.php?category=mario-games > domain.com/category/mario-games
game details : domain.com/index.php?game=mario-game > domain.com/mario-game.html
featured : domain.com/featured.php > domain.com/featured
pages : domain.com/page.php?id=contact > domain.com/page/contact

      

After searching the internet, I successfully follow the rewrite rules. But my old URLs are still available. How can I redirect and rewrite old urls to new ones?

server {
    listen       80;
    server_name  domain.com;
    return       301 http://www.domain.com$request_uri;
}

server {
    listen       80;
    server_name  www.domain.com;
    root   /usr/share/nginx/domain;

    index  index.php index.html index.htm;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;


        location / {
        rewrite ^/(.*).html$ /index.php?game=$1 last;
        }
        location /category {
        rewrite ^/(.+)/$ /$1 permanent;
        rewrite ^/category/(.*)$ /index.php?category=$1 last;
        }
        location /page {
        rewrite ^/(.+)/$ /$1 permanent;
        rewrite ^/page/(.*)$ /page.php?id=$1 last;
        }
        location /featured {
            rewrite ^/(.+)/$ /$1 permanent;
            rewrite ^/(.*) /featured.php last;
        }






    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }

    location ~ \.php$ {
        try_files  $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }


    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { log_not_found off; access_log off; }

    location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        expires max; log_not_found off; access_log off;
    }
    location ~* \.(js|jpg|png|css)$ {

        expires 30d;
    }


}

      

+3


source to share





All Articles