1

My website runs perfectly when deployed to an Apache server. It relies on this .htaccess file:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /c/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Now I try to do some testing using the PHP 7.2.2 Development Server on localhost, which I understand does not make use of the .htaccess file because it doesn't rely on Apache.

I learned that it is possible to create a router.php script in the site root and then launch the local development server like this:

php -S localhost:8080 router.php

The router.php script is supposed to handle all the routing that the .htaccess file would normally handle on the Apache server. I tried using a sample router.php script found here, but it doesn't work correctly for my setup. I think the problem is that my .htaccess file utilizes RewriteBase /c/ to provide a new base URL for the rewrite, but the router.php script does not have a similar base URL. The problem that occurs with the given router.php script is that it is trying to rewrite all URLs, not just the ones in the new base URL of /c/.

My question is: How should I prepare the router.php file in order to handle my specific .htaccess file noted above?

DanielAttard
  • 3,467
  • 9
  • 55
  • 104
  • 1
    The question you link has some pretty thorough explanations and you don't explain what exactly isn't appropriate for you. Apache is a full-fledged HTTP server and PHP builtin server is a simple developer tool: you can't mimic 100% of the functionality of the former with the latter. – Álvaro González Nov 03 '19 at 16:33
  • Thanks Alvaro. I edited the question to show the specific problem I am experiencing with the `router.php` script. – DanielAttard Nov 03 '19 at 19:33
  • It seems you're having a problem (rather than miss a feature). I'm not fully sure of what your problem is but perhaps you're missing the `-t` option ([reference](https://www.php.net/manual/en/features.commandline.webserver.php)). See also the [dots issue](https://bugs.php.net/bug.php?id=61286). – Álvaro González Nov 05 '19 at 11:01

0 Answers0