Nginx lock|redirect url files

Asked

Viewed 517 times

0

I am creating a url shortener in my subdomain ex: (go.domain.com) to serve as an external reference, example:

// a url de uma pagina (extensa)
www.domain.com/user-2124532544454343dgfs-pages-artes-31234124141241241212xxxx

// ficaria assim:
go.domain.com/world-arts

Well this example ta well "crude" but the problem is that I need to receive the url via $_GET in the "go" subdomain and as the "shortened" url points to a subdirectory in "go" use try_files with emphasis on directories $uri/ in the server block settings nginx to complete the processing of the ex request:

location / {
    try_files $uri $uri/ /index.php?l=$request_uri;
}

Where "l" (Location) is the reference to access the $_GET with PHP and search in the database so that if there is record redirect.

So far so good once the "shortened" url is correctly accessed bad when launching for example "go.domain.com/image.png" falls into error 404 however 404 is reserved for a global (notfound) error within the project.

How to check if the url has a dot (.) or other invalid character in any part of it? And so return the index with a $_GET to catch that mistake?

The closest I came was with this rule:

error_page 400 /index.php?error=bad;

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|html|htm)$ {
   return 400;
}

However it is not possible to predict all possibilities, a simple /hgaasd.aaa would be enough to launch an error 404.

In the case in question the characters allowed would be alpha-numeric and @_-

  • Summarizing you that a rule so that in the end you have only /alfa-numéricos e @_-? that?

  • And that I can launch the non-compatible entries in an error other than 404

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.