Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using phprouter for project in subdirectory #42

Closed
GiacomoPope opened this issue Nov 15, 2022 · 5 comments
Closed

Using phprouter for project in subdirectory #42

GiacomoPope opened this issue Nov 15, 2022 · 5 comments

Comments

@GiacomoPope
Copy link

Hi,

If I have a project in

example.com/new_project

and I want to do routing (e.g.)

example.com/new_project/user/name => example.com/new_project/user.php?name=name

Do I need to change the code? I can't seem to get it working, all I get is blank html when I do the static routing.

@madanielecd
Copy link

madanielecd commented Nov 16, 2022

Hi Jack,

You could try this.

  1. Place all the phprouter files (so also the .htaccess file) in your subfolder
  2. Edit the router.php file accordingly:

comment out this line
// $request_url = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);

replace it with
// start add
$thisPart = explode(basename(getcwd()), $_SERVER['REQUEST_URI']);
$fromSubBase = (isset($thisPart[1])) ? $thisPart[1] : $thisPart[0];
$request_url = filter_var($fromSubBase, FILTER_SANITIZE_URL);
// end add

@phprouter
Copy link
Owner

Hi @madanielecd, I have tried your solution to make it part of the router, though it does not work. Can you please let me know how you expect this to be used?

@madanielecd
Copy link

madanielecd commented Dec 19, 2022

Hi @phprouter,

Well I'm not sure, but could it be server config dependant? Is your (Apache) server not responding to the .htaccess in a subfolder?
And fe on nginx it won't work because there is no .htaccess support.

@phprouter
Copy link
Owner

Maybe this works:

@phprouter
Copy link
Owner

PhpRouter is intended to be used directly under the root/domain folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants