Comments (4)
For others, like me who are looking for an actual example of a custom router for pretty URL's, this is what I came up with that works:
router.php
<?php
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$relativePath = getenv('PHP_SERVER_RELATIVE_PATH');
$fullPath = $_SERVER["DOCUMENT_ROOT"] . $relativePath . $path;
if (!file_exists($fullPath) || is_dir($fullPath)) {
file_put_contents("php://stderr", sprintf("[%s] %s", date("D M j H:i:s Y"), "[404] $path - No such file or directory "));
}
else {
file_put_contents("php://stdout", sprintf("[%s] %s", date("D M j H:i:s Y"), "[200] $path"));
}
// Support for Pretty URL's
$ext = pathinfo($fullPath, PATHINFO_EXTENSION);
if ($ext === '' && substr($fullPath, -1) !== '/') {
require($fullPath . '.php');
return;
}
return false;
You can add the custom router in the PHP Server Configuration
via:
NOTE: I did need to restart the PHP server for the changes to take effect.
from vscode-phpserver.
Hmm... yeap, you are right. I'll take a look at the problem and I'll see what I can do.
Thanks @rclafferty !
Edit: I think you could solve it using a custom router script (There is an extension option to specify a custom router script), but I'll try to see if I can solve the problem without having to do that.
The script could be something similar to this
from vscode-phpserver.
Hi @brapifra. Is there any update on this issue yet? I tried the server script as you referenced, but did so very briefly and could not make it work yet. I will keep trying.
from vscode-phpserver.
Hi @rclafferty. I'm afraid that the custom router is the only possible solution :(
The script I've linked you should work, but let me know if you need anything else!
from vscode-phpserver.
Related Issues (20)
- [Fixed] Requested resource not found on server? HOT 1
- PHP Server not working after brew upgrade to php 7.4 in OSX?
- Extension issue
- The requested resource was not found on this server, using .htaccess.
- Keeps loading old version of html file when pressing serve button top right
- [Feature] Keep track of server state to greatly improve usability of extension
- Unable to serve remote folder
- Error HOT 1
- Serve Project Issue HOT 1
- Would be nice to have setting for environment variables HOT 1
- Requesting to have this also published to open-vsx.org for VSCodium HOT 1
- PHP Not Found (Ubuntu) HOT 3
- How should I solve this problem?�����ҳ: 936
- How can I activate debug?
- test
- Busy port when closing window
- nội thất
- nội thất
- how to open in a new tab instead of a new browser window
- PHP not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-phpserver.