.htaccess and rewriting rules on PHP server

2

I'm developing a php microframwork, and I'm using php's built-in server (php-127.0.0.1.18000 -t public) with root directory in public / folder.

I do not know if .htaccess works or is running on this server.

When accessing a non-root ("/") path such as "/ properties", the path of CSS files, images, and the like is overlapping the route, such as: "/ / css / ... "where the normal should be:" / ext / css /...".

Accessing the "/ properties" route (WORKING PROPERLY):

[Sat Nov 17 20:35:12 2018] ::1:34630 [200]: /propriedades
[Sat Nov 17 20:35:12 2018] ::1:34634 [200]: /ext/css/core.css
[Sat Nov 17 20:35:12 2018] ::1:34636 [200]: /img/logo02.svg
[Sat Nov 17 20:35:12 2018] ::1:34638 [200]: /img/default-image.png

Accessing the path "/ properties /" (PROBLEM):

[Sat Nov 17 20:35:10 2018] ::1:34620 [200]: /propriedades/
[Sat Nov 17 20:35:10 2018] ::1:34622 [404]: /propriedades/ext/css/core.css - No such file or directory
[Sat Nov 17 20:35:10 2018] ::1:34626 [404]: /propriedades/ext/js/core.js - No such file or directory
[Sat Nov 17 20:35:11 2018] ::1:34628 [404]: /propriedades/ext/js/core.js - No such file or directory

Routes are picked up and handled by the route class of the system. Here is the .htaccess file:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Can anyone at least give me some idea of what I should try to do to solve it?

    
asked by anonymous 18.11.2018 / 00:50

1 answer

1
  

I do not know if .htaccess works or is running on this server.

The internal php server will not consider .htaccess

  

Can anyone at least give me some idea of what I should try to do to solve it?

Regardless of .htaccess you need to fix how your HTML references CSS files. You're probably using relative links:

<link rel="stylesheet" type="text/css" href="ext/css/core.css">

In the root of the site this works well, but when accessing another route, the browser sends the segment of the url together.

You can reference this file from the root, so it will work on any route:

<link rel="stylesheet" type="text/css" href="/ext/css/core.css">

It is also interesting to generate the complete URL, and in the future allow it to be configurable for a different domain (using a CDN for example) to have more control:

<link rel="stylesheet" type="text/css" href="http://localhost/ext/css/core.css">
    
18.11.2018 / 02:07