rohitkrishna-marneni opened a new issue, #12023:
URL: https://github.com/apache/apisix/issues/12023

   ### Description
   
   I want to create a plugin where if upstream status is 404, I will be able to 
specify a custom 404 page and it should go there.
   
   So this is what I have so far.
   
   My apisix configuration for route
   ```yml
   services:
     - name: my-service
       upstream:
         pass_host: pass
         nodes:
           - host: my-api.com
             port: 80
             weight: 1
             priority: 0
         type: roundrobin
         scheme: http
         name: my-api
         hash_on: vars
         timeout:
           send: 10
           read: 60
           connect: 2
       routes:
         - name: my product page route
           hosts:
             - "mysite.com"
           uris:
             - /shop/products/*
           priority: 0
           plugins:
             custom-404-redirect:
               redirect_url: /us/en/footer/terms-conditions.html
   ```
   
   And my plugin code is as shown below
   
   ```lua
   local core = require("apisix.core")
   local ngx = ngx
   
   local plugin_name = "custom-404-redirect"
   
   local schema = {
       type = "object",
       properties = {
           redirect_url = {type = "string", minLength = 1}
       },
       required = {"redirect_url"}
   }
   
   local _M = {
       version = 0.1,
       priority = 1010,  -- set the plugin priority, higher means earlier 
execution
       name = plugin_name,
       schema = schema
   }
   
   function _M.check_schema(conf)
       return core.schema.check(schema, conf)
   end
   
   function _M.header_filter(conf, ctx)
       if ngx.status == 404 then
           ngx.status = 302
           ngx.header["Location"] = conf.redirect_url
           ngx.log(ngx.ERR, "Redirecting to custom 404 page: ", 
conf.redirect_url)
           ngx.exit(ngx.HTTP_MOVED_TEMPORARILY)
           end
   end
   
   return _M
   ```
   
   But this is not working and simply throwing a 500 status code instead of 
going to a 404 as expected. Is it not possible to do it via plugin?
   
   ### Environment
   
   - APISIX version (run `apisix version`):
   - Operating system (run `uname -a`): Ubuntu
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to