Htaccess RewriteRule saves query string

I have a RewriteRule like this:

RewriteRule ^thesection$ /sections.php [L] RewriteRule ^thesection/(.*)$ /sections.php?show=$1 [L] 

so if i enter domain.com/thesection → it works fine

but !, if I enter domain.com/thesection/hello , it redirects to domain.com/thesection?show=hello

I do not know what I am doing wrong, and I spent a lot of time searching the Internet. Please, help!

Thanks in advance

+6
source share
1 answer

Try it and let me know

 RewriteEngine On RewriteRule ^thesection/?$ /sections.php [L,QSA] RewriteRule ^thesection/([a-z0-9\-_]+)/?$ /sections.php?show=$1 [L,QSA] 

this will redirect domain.com/thesection/hello to sections.php?show=hello

QSA flag means:

This flag causes the rewrite mechanism to add a query string string to a substitution string to an existing string instead of replacing It. Use this when you want to add additional data to the query string using rewrite rule.

so that you can add additional parameters, for example: http://www.domain.com/thesection/hello/?page=1 this will be displayed:

 Array ( [show] => hello [page] => 1 ) 
+9
source

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


All Articles