1

I am new to php stuff, so the question might be a bit stupid:

index.php

<?php

include "rest/db.php" ;
$db = OpenCon();

$request = $_SERVER['REQUEST_URI'];

switch ($request) {
    case '/' :
        require __DIR__ . '/home.php';
        break;
    case '/supply' :
        require __DIR__ . '/supply.php';
        break;
    case '/about' :
        require __DIR__ . '/about.php';
        break;
    case '/careers' :
        require __DIR__ . '/careers.php';
        break;

    ......//some more stuff

    default:
        http_response_code(404);
        require __DIR__ . '/404-page.php';

.htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]

1 question:
I need to handle request to supply.php?page=5(or supply.php?page=5&offset=5). How do I need to change index.php and htaccess for that?

2 question:
I have admin template written in angular and hosted on the same hosting as this website(which is in php). Angular admin project is in /adminv1 folder. The problem with it is that, when I do refresh the page, it goes to 404 page and loses the styles. I guess this is happening because of the request handling in index.php. What would be the simplest way to solve it?

admin panel working

admin panel after refresh

Thanks in advance!

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Sik
  • 11
  • 1
  • 1. Easiest way would be, if you do not evaluate `REQUEST_URI`, but pass the originally requested path as an extra parameter. `RewriteRule ^(.+)$ index.php?script=$1 [QSA,L]`. `$_GET['script']` should now contain `supply.php` with your given example URL. – CBroe Jan 20 '21 at 10:29
  • 2. Exclude everything below the `/adminv1` path from your rewriting, https://stackoverflow.com/a/13842523/1427878 – CBroe Jan 20 '21 at 10:31
  • I suggest you take a look at the documentation to learn about the different content you can find in the `$_SERVER` superglobal variable. You certainly will be able to implement query handling yourself after that: https://www.php.net/manual/en/reserved.variables.server.php – arkascha Jan 20 '21 at 10:53

0 Answers0