Welcome! Log In Create A New Profile

Advanced

Nginx rewrite

Posted by allsociety 
Nginx rewrite
March 04, 2012 08:48AM
Hey whats up guys i just need help with a small thing.
Say a user types
example.com/@example
I would like it to just process at the index.php page but still have the URL with the /@example
If anyone could lend a hand with this that would be AWESOME!
Basically it would be fine if the user types in the @example and is put on the index page and the url still looks like example.com/@example

Also this would be a great solution too if i could just replace the @ symbol with a #/@ kinda like twitter does it.

Thanks again guys if you could help out!



Edited 2 time(s). Last edit at 03/04/2012 08:56AM by allsociety.
Re: Nginx rewrite
March 24, 2012 05:50PM
One solution could be to use the try_files method like the following

server {
....
location / { try_files $uri /index.php?uri=$request_uri; }
location ~ \.php$ { include fastcgi_params; }
...
}

In short, this will make nginx server all actual files right away but instead of throwing a 404 on a request for "/@example" nginx will serve "/index.php?uri=@whatever" through the PHP fastcgi setup you have. This method doesn't do any redirects and it's faster and uses less ressources than using a rewrite rule and/or if statements.

Documentation: http://wiki.nginx.org/NginxHttpCoreModule#try_files

Good luck.
//Morten



Edited 1 time(s). Last edit at 03/24/2012 05:51PM by morten.
Re: Nginx rewrite
March 26, 2012 06:11AM
OMFG I LUVE U! HAVE MY CHILDREN!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 150
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready