0

Want to rewrite nginx with setup such as www.example.com/abc/xyz/test/

redirect to www.example.com/abc/xyz/test.php So want to make an rewrite rule which will work for all pages with that url like so i tried this one which works

 location ~* /abc/xyz/.*/$ { rewrite ^/abc/xyz/.*/$ /abc/xyz/test.php last; } 

this rule works but it always redirect to test.php want to make it dynamic so that it will also work for test2.php test3.php when in url it will be like www.example.com/abc/xyz/test2/ and so on as we have 100 pages so i need to write 100 rules if no solution found. Any help will be appreciate.

1 Answer 1

0

try_files should be sufficient.

location / { try_files $uri $uri.php; } 
1
  • in / we are using this to remove .php lines location / { try_files $uri $uri/ @extensionless-php; index index.html index.htm index.php; } location @extensionless-php { rewrite ^(.*)$ $1.php last; } Commented Sep 6, 2023 at 10:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.