Y
Y
Ysery2021-10-12 21:43:58
htaccess
Ysery, 2021-10-12 21:43:58

htaccess to cut off including and only the symbol "?", how?

Good day, dear experts.

I am using this code:

<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} !(^|&)srp=
RewriteCond %{QUERY_STRING} !(^|&)q=
RewriteRule ^(.+?)\.html$ https://%{HTTP_HOST}/$1.html? [L,R=301]
</IfModule>

<IfModule mod_rewrite.c>
RewriteRule ^(.+?)\.html(?!/amp/).+$ https://%{HTTP_HOST}/$1.html? [L,R=301]
</IfModule>


It cuts everything after ...some-link.html, with the following exceptions,
if the link contains ...some-link.html?srp=123either or ...some-link.html?q=123or ...some-link.html/amp/

However, if the link is like this ...some-link.html?(a question mark at the end and nothing else), then this character will not be cut off.

What needs to be corrected in the code so that the clipping of this very question mark is still captured?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-10-12
@dodo512

It suffices to change the condition toRewriteCond %{QUERY_STRING} !^$RewriteCond %{THE_REQUEST} \?

<IfModule mod_rewrite.c>
RewriteCond %{THE_REQUEST}  \?
RewriteCond %{QUERY_STRING} !(^|&)srp=
RewriteCond %{QUERY_STRING} !(^|&)q=
RewriteRule ^(.+?)\.html$ https://%{HTTP_HOST}/$1.html? [L,R=301]
</IfModule>

<IfModule mod_rewrite.c>
RewriteRule ^(.+?)\.html(?!/amp/).+$ https://%{HTTP_HOST}/$1.html? [L,R=301]
</IfModule>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question