K
K
kpot19792016-08-02 22:57:30
htaccess
kpot1979, 2016-08-02 22:57:30

How to make a Redirect 301 if there is one in the URL?

How can I redirect through htaccess for several addresses, for example:
www.mysite.ru/category1/?page=1 to www.mysite.ru/category1/
www.mysite.ru/category2/?page=1 to www.mysite. ru/category2/
www.mysite.ru/any-category/?page=1 to www.mysite.ru/any-category/
etc.
Tried like this:

RewriteRule ^category1/?page=1$ www.mysite.ru/category1/ [R=301,L]
RewriteRule ^category2/?page=1$ www.mysite.ru/category2/ [R=301,L]
RewriteRule ^any-category/?page=1$ www.mysite.ru/any-category/ [R=301,L]

but nothing works. I tried escaping \?, but that didn't help either.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2016-08-03
@kpot1979

# 301 --- www.mysite.ru/any-category/?page=1 => www.mysite.ru/any-category/
RewriteCond %{QUERY_STRING} (^|&)page=1($|&)
RewriteRule ^www\.mysite\.ru/any-category/$ /www.mysite.ru/any-category/? [L,R=301]

And in your case, it's easier to go here
https://donatstudios.com/RewriteRule_Generator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question