M
M
mrgnv2021-04-29 21:01:48
htaccess
mrgnv, 2021-04-29 21:01:48

How to write a Rewrite rule?

We have:


RewriteRule ^([^/]*)/?$ index.php?module=category&url=$1 [L,QSA] #RewriteRule category
^([^/]*)/([^/]*)/?$ index. php?module=page&url=$1 [L,QSA] #category/category page
RewriteRule ^/?$ index.php?module=page&url=main [L,QSA] #main page


current nesting of URLs:
moysite.rf/
moysite.rf/category
moysite.rf/category/category-page The

code example above works, but there is an admin folder in the main directory , these rules (rewriterule) do not allow accessing the admin panel directly as a directory What did I miss and how can I fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2021-04-29
@dodo512

RewriteEngine on

RewriteRule ^admin($|/) - [L]

RewriteRule ^$ index.php?module=page&url=main [L,QSA]
RewriteRule ^([^/]*)/?$ index.php?module=category&url=$1 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?module=page&url=$1 [L,QSA]

Z
Zettabyte, 2021-04-30
@Zettabyte

I once had a similar problem. Here is an alternative option, in addition to the proposed one - add the following lines before your rules:

RewriteCond %{REQUEST_URI} "admin/" [OR]
RewriteCond %{REQUEST_URI} "admin"
RewriteRule (.*) $1 [L]

Separately, I note that in my case there was a PHP request handler in the excluded folder, there is no information about this for your case.
PS
By the way, another option is to add a RewriteRuleline before each of yours
RewriteCond %{REQUEST_FILENAME} !-d

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question