V
V
Viktor Trunov2021-04-24 06:00:41
htaccess
Viktor Trunov, 2021-04-24 06:00:41

How to redirect page URL with Get parameters to without GET parameters via htaccess?

Hello! Please help me set up a redirect via .htaccess with the following URLs:

Исходный: /vybiraem-videokartu-pod-materinskuyu-platu-i-protsessor/comment-page-27/?unapproved=4135&moderation-hash=da912872c1d73732f097d0a3349b2920
Конечный: /vybiraem-videokartu-pod-materinskuyu-platu-i-protsessor/


We need a universal rule that will work for all pages and will cut everything starting with "comment-page" in the URL through 301 redirects to without "comment-page" and everything else.

Did it like this:
RewriteCond %{QUERY_STRING} ^(.*)comment-page^(.*) [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]

But it does not work as it should, the address remains: ?unapproved=4135&moderation-hash=da912872c1d73732f097d0a3349b2920

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zettabyte, 2021-04-24
@Zettabyte

We need a universal rule that will work for all pages ... But it does not work as it should, it remains

Add ?a (question mark) at the end of your RewriteRule - this removes all parameters altogether.
Also, if you have Apache 2.4.0 or newer, you can use the flag QSD, i.e. your second line will look like this: PS And, by the way, maybe I didn’t understand something, but you don’t have in , but in . RewriteRule ^(.*)$ /$1?%1%2 [R=301,L,QSD]
comment-page%{QUERY_STRING}%{REQUEST_URI}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question