简体   繁体   中英

Forward request FROM custom index.php

I have an existing web application that is not using any framework and I would like to add .env support to it. In order to facilitate this I thought it might be best to send all requests to an index.php file, which would register the .env contents in the $_ENV array, then forward the original request on to its intended destination.

As an example, someone would try to go to http://test.com/dashboard.php , and would then using an htaccess, file be redirected to http://test.com/index.php . There, the environment variables would be registered for every request and I would like to send that whole request back on to http://test.com/dashboard.php .

If there is an easy way to accomplish this, or a better solution to the current problem I would appreciate the input. I am willing to use the Symfony Request/Response objects if that makes things easier.

The easiest solution indeed seems to be what you describe: Force all requests to go through index.php, register your environment variables, then simply include dashboard.php. Whether this is the most solid approach can be discussed.

Using Symfony's HttpFoundation is probably a more solid construction, however this means you'll probably have to update your existing code as well. While I'll always advice a more solid approach based on open source components, the investment is a bit bigger and I don't know your context so I don't know whether this is acceptable.

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