Query Strings & Mod ReWrite

I am not too inexperienced with ReWrite (but not a wizard), so I was hoping that someone could help me.

RewriteRule ^$ index.php?page=home [NC]
RewriteRule ^adm$ index.php?page=adm_home [NC]
RewriteRule ^adm/stats index.php?page=adm_stats [NC]

Above is a snippet of my .htaccess file. As you can see, when someone visits http://www.example.com/adirectory/ , does he actually call index.php? Page = home, similarly, if someone goes to http://www.example.com/adirectory/adm/ he still calls index.php? page = adm_home in "adirectory".

What I want to achieve is this: I want to be able to display warnings on my pages, and for this I just want to add alert = n (where n is a number) and thus a redirect like index.php? page = home & alert = n

However, I can’t understand how this can be done, the regular expression is confusing for me. Ask for help.

+3
source share
1 answer

You can set the QSA flag to automatically add the originally requested query string to a new one:

RewriteRule ^$ index.php?page=home [L,QSA]
RewriteRule ^adm$ index.php?page=adm_home [L,QSA]
RewriteRule ^adm/stats$ index.php?page=adm_stats [L,QSA]
+6
source

Source: https://habr.com/ru/post/1702368/


All Articles