R
R
RoffDaniel2019-07-15 16:28:19
PHP
RoffDaniel, 2019-07-15 16:28:19

Why is the CNC not working properly?

Hello. I have a problem with CNC links.
I have pages like:


?page=admin
?page=admin&adminpage=users
?page=admin&adminpage=users&action=add
?page=admin&adminpage=news
?page=admin&adminpage=news&action=add

Here is the complete .htaccess code:
RewriteEngine On

RewriteBase /

AddDefaultCharset UTF-8

ErrorDocument 401 /site-system/errors/401.php
ErrorDocument 403 /site-system/errors/403.php
ErrorDocument 404 /site-system/errors/404.php
ErrorDocument 500 /site-system/errors/500.php
#==============================================================
RewriteRule ^([^/]*)/$ /index.php?page=$1 [L]
#===========================NEWS===============================
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?page=$1&url=$2 [L]
#==============================================================
#===========================ADMIN==============================
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?page=$1&adminpage=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /index.php?page=$1&adminpage=$2&action=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ /index.php?page=$1&adminpage=$2&action=$3&id=$4 [L]
#==============================================================
# RewriteRule ^logout/$ /site-system/functions/logout.php [L]
#==============================================================

############################################################################
#### Убираем слеши в конце URL для статических файлов (содержит точку)  ####
############################################################################
RewriteCond %{REQUEST_URI} \..+$
   # Если файл содержит точку.
RewriteCond %{REQUEST_FILENAME} !-d
   # И это не директория.
RewriteCond %{REQUEST_FILENAME} -f
   # Является файлом.
RewriteCond %{REQUEST_URI} ^(.+)/$
   # И в конце URL есть слеш.
RewriteRule ^(.+)/$ /$1 [R=301,L]
   # Исключить слеш.

############################################################################
#### Добавляем слеш(/), если его нет, и это не файл.                    ####
############################################################################
RewriteCond %{REQUEST_URI} !(.*)/$
   # Если слеша в конце нет.
RewriteCond %{REQUEST_FILENAME} !-f
   # Не является файлом.
RewriteCond %{REQUEST_URI} !\..+$
   # В URL нет точки (файл).
RewriteCond %{REQUEST_URI} ^(.+)$
 # В URL есть хоть один символы
RewriteRule ^(.*)$ $1/ [L,R=301]
   # Добавляем слеш в конце.

Now a question. Why when I enter "/admin/users/", the main page of the admin panel "?page=admin" opens for me. Same with /admin/news/', displays the main page. But if I enter "/admin/users or news/add", then the required page opens...
Here's another PHP code attached:
<?php


class admin extends engine_admin {
    public function get_content() {
        if (!isset($_GET['adminpage'])) {
            echo 'test admin index';
        } else {
            if ($_GET['adminpage']) {
                $page = $_GET['adminpage'];
                if ($page == 'users') {
                    if (!isset($_GET['action'])) {
                        echo '
                        test 2 users list
                        ';
                    } else {
                        if ($_GET['action']){
                            $action = $_GET['action'];
                            if ($action == 'add') {
                                echo '
                                test 2 add new user
                                ';
                            }
                        }
                    }
                } else if ($page == 'news') {
                    if (isset($_GET['action'])) {
                        echo '
                        test 3 news list
                        ';
                    } else {
                        if ($_GET['action']){
                            $action = $_GET['action'];
                            if ($action == 'add') {
                                echo '
                                test 3 add new news
                                ';
                            }
                        }
                    }
                }
            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RoffDaniel, 2019-07-15
@RoffDaniel

In general, maybe right, or maybe not, but I solved this problem in this way:
RewriteRule ^admin/([^/]*)/$ /index.php?page=admin&adminpage=$1 [L]
RewriteRule ^admin/([^/]*)/([^/]*)/$ /index. php?page=admin&adminpage=$1&action=$2 [L]
RewriteRule ^admin/([^/]*)/([^/]*)/([^/]*)/$ /index.php?page=admin&adminpage =$1&action=$2&id=$3 [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question