N
N
Nikolay Savelyev2019-08-30 21:48:00
PHP
Nikolay Savelyev, 2019-08-30 21:48:00

How to decide that parameters are passed through htaccess?

Hello everyone, how to pass GET parameters to htaccess using switch case ?
There is such a routing.
/index.php

# Шапка
include('inc/head.php');

# Страницы
$url = explode('?', $_SERVER['REQUEST_URI'], 2);

switch($url[0]){
    case '/' : require __DIR__ . '/pages/main.php';break; // Главная
    case '/login' : require __DIR__ . '/pages/login.php';break; // Вход
    case '/reg' : require __DIR__ . '/pages/reg.php';break; // Регистрация
    case '/about' : require __DIR__ . '/pages/about.php';break; // О проекте
    default: require __DIR__ . '/404.php';break; // 404
}

# Подвал
include('inc/foot.php');

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

But the problem is not getting the address
Example:
case '/link/edit/12' : require __DIR__ . '/pages/account/link.php';break; // Links
are https://localhost/link.php?edit=12
to beauty https://localohost/link/edit/12
what is needed in htaccess for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Savelyev, 2019-08-31
@Jumast

Issue resolved!
We get a link like /link/edit/132
remove the extra

$link_add = mb_eregi_replace('[^0-9 ]', '', $uri[0]); // получаем число

Give the number here
Now the link works with /link.php?advedit=123
in .htachchess
/link/edit/123

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question