Y
Y
Ysery2021-09-21 00:03:58
htaccess
Ysery, 2021-09-21 00:03:58

Clipping question mark via htaccess?

Good day.

The code found on the web works almost perfectly, cuts off "query strings" except for those that are actually used on the site (p= and s=), and also does not cut anything if the work is done in the site's admin panel.

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{QUERY_STRING} !=""
 RewriteCond %{QUERY_STRING} !^p=.*
 RewriteCond %{QUERY_STRING} !^s=.*
 RewriteCond %{REQUEST_URI} !^/wp-admin.*
 RewriteRule ^(.*)$ /$1? [R=301,L]
</IfModule>


But here one moment seems to me a defect, namely, ignoring the "question mark" symbol, i.e. if, for example, the link contains something like this - test.ru/nazvanie? , then the question mark will not be cut off, but it will work if, for example, it will be like this test.ru/nazvanie?123 and the final link will be test.ru/nazvanie

character "?"), if at the end there is only a question mark?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-09-21
@dodo512

There's the first RewriteCond Just replace with
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{THE_REQUEST} \?

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{THE_REQUEST}  \?
 RewriteCond %{QUERY_STRING} !^p=.*
 RewriteCond %{QUERY_STRING} !^s=.*
 RewriteCond %{REQUEST_URI}  !^/wp-admin.*
 RewriteRule ^(.*)$ /$1? [R=301,L]
</IfModule>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question