I have an email verification script that looks like this:
http://example.com/v/index.php?t=TOKEN_EMAILED_TO_CLIENT
And I want it to look like this:
http://example.com/v/TOKEN_EMAILED_TO_CLIENT
Essentially just removing the index.php?t=
portion of the URL, but still allowing the index.php file to process the token.
I have tried the following three settings and none of them have worked:
location /v/ {
try_files index.php$args;
}
The above results in a failed nginx.conf file
location ^~ /v/ {
try_files /v/index.php?q=$uri;
}
The above results in a failed nginx.conf file
location ^~ /v/ {
rewrite ^/v/index.php?q=(.*)$ $1 permanent;
}
The above passes nginx.conf file requirements, but still does not do what I would like. It shows a 404 error when visiting http://example.com/v/TOKEN_EMAILED_TO_CLIENT
Any help would be greatly appreciated.
First thing,
^~
usage is not necessary if you don't have any regex matching this pattern prior to the location your are defining. What you want to do is basically have proper URIs and rewrite them to pass an argument to your php application. In this case, the appropriate solution is using rewrites.The thing you missed in there is that the URI you are matching against is the first argument to the rewrite directive so it can obviously not match
^/v/index.php?q=(.*)$
since it equals/v/TOKEN_EMAILED_TO_CLIENT
. The second argument to the rewrite directive is the URI to rewrite to.So given you have somewhere a location of this kind which handles
.php
files :Then you need this location block instead :