S
S
Sailaubai Shyngys2016-02-05 17:28:05
Apache HTTP Server
Sailaubai Shyngys, 2016-02-05 17:28:05

How to implement multi-level CNC using .htaccess?

Good evening. A dead end yuzaya in Google question. The point is this.
There are links like:
site.ru/?menu=[-a-zA-Z]&submenu=[-a-zA-Z]
site.ru/?menu=[-a-zA-Z]&submenu=[-a- zA-Z]&city=[-a-zA-Z]
Implemented like this:
RewriteRule ^([-a-zA-Z_]+)/([-a-zA-Z_]+)/([-a-zA- Z_]+)/?$ index.php?menu=$1&submenu=$2&city=$3 [QSA,L]
RewriteRule ^([-a-zA-Z_]+)/([-a-zA-Z_]+) /?$ index.php?menu=$1&submenu=$2 [QSA,L] The
question is what to do when there is no submenu parameter in the link in this form site.ru/?menu=[-a-zA-Z]&city=[ -a-zA-Z] . Here there will be confusion, since the city parameter can be presented as a submenu
. Any suggestions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Kulikovsky, 2016-02-06
@by25

Usually such functionality is not done through .htaccess.
All urls are passed to the front controller (index.php, for example), and it decides which controller/code to call.
Example .htaccess to redirect all urls to index.php:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question