質問

I am currently battling with the existing documentation of the rewrite rule in nginx. I have a hard time finding anyone else who have done this aswell.

What I want is rather simple. When I visit http://mypage.com/group.php I want to be redirected to http://mypage.com/group/. I want it to read group.php ofcourse when I visit /group/

I've played around a bit with locations in my server config but never got it to work.

location /group/ {
     rewrite ^/group(.*) group.php
}

I can't seem to get this rule.

役に立ちましたか?

解決

Try this:

  1. It redirects /group.php to /group/
  2. Rewrite everything in /group/ to /group/group.php

This assumes group.php exists in /group/group.php.

rewrite ^/group\.php$ /group/ redirect;
rewrite ^/group/ /group/group.php last;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top