Code Monkey home page Code Monkey logo

Comments (4)

manifestinteractive avatar manifestinteractive commented on June 12, 2024 1

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:

php-server-config

NOTE: I did need to restart the PHP server for the changes to take effect.

from vscode-phpserver.

brapifra avatar brapifra commented on June 12, 2024

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.

rclafferty avatar rclafferty commented on June 12, 2024

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.

brapifra avatar brapifra commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.