I want to remove .php anywhere it finds it from the visible url but still use the routing functions i wrote.
Goal: shop/index.php/product/test -> shop/index/product/test or even better shop/product/test but also shop/contact.php -> shop/contact
.htacess atm works with php extension at the end of the url but not if i want to replace shop/index.php/product/test to shop/index/product/test. Tried many .htacess settings but if i change them, to work with shop/index/product/test shop/contact doesnt work and gets a 404
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
routes.php
<?php
$url = $_SERVER['REQUEST_URI'];
$indexPHPPosition = strpos($url,'index.php');
$baseUrl = substr($url,0,$indexPHPPosition);
$route = null;
if(false !== $indexPHPPosition){
    $route = substr($url,$indexPHPPosition);
    $route = str_replace('index.php','',$route);
}
if(!$route){
    require __DIR__.'/templates/index.php';
    exit();
}
if(strpos($route,'/cart/add/') !== false){
    $routeParts = explode('/',$route);
    $productId = (int)$routeParts[3];
    header("Location: ".$baseUrl."index.php");
    exit();
}
if(strpos($route,'/product/') !== false) {
    $routeParts = explode('/', $route);
    if (count($routeParts) !== 3) {
        echo "Ungültige URL";
        exit();
    }
    $slug = $routeParts[2];
    if (0 === strlen($slug)) {
        echo "Ungülites Produkt";
        exit();
    }
    require "includes/functions.inc.php";
    require "includes/dbh.inc.php";
    $product = getProductBySlug($slug,$conn);
    if (null === $product) {
        echo "Ungülites Produkt";
        exit();
    }
    require_once __DIR__ . '/templates/watchdetail.php';
    exit();
}
