简体   繁体   中英

Rewrite all PHP urls to a specific url in nginx

How can I rewrite all PHP requests to a single, specific url?

For example these urls

https://somesite.com/thing.php

https://somesite.com/dir/ (contains index.php)

Would be redirected to this: https://somesite.com/dir/someotherthing.php

I also want to keep the client-side URL untouched:

For example https://somesite.com/thing.php should still be the same URL instead of instantly changed to https://somesite.com/dir/someotherthing.php

Another question, would $_SERVER['REQUEST_URI'] in PHP still be the client-side's request URL when I do this? And if not, how can I pass it to https://somesite.com/dir/someotherthing.php ?

You can't redirect the client without touching client-side URL via server-side.

Use AJAX for that. The behavior you are looking for is similar in some ways to the way a SPA application interacts with an API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM