Answer the question
In order to leave comments, you need to log in
How to redirect with .htaccess?
Good afternoon.
Can you please tell me how to make a 301 redirect using .htaccess?
There is a "city" page which receives data via &_GET and displays information.
The page looks like: site.ru/city?name=Toronto
If I just go to the page site.ru/city
, I will get an error and in this case I need to redirect to the main page. If I make a 301 redirect in .htaccess RedirectMatch 301 /city /
, then in principle everything works, when I go to site.ru/city I get a redirect.
BUT if I want to go to the page , site.ru/city?name=Toronto
I get the address site.ru/?name=Toronto
, the phrase "city" is removed and that's it.
How to make a correct redirect?
Answer the question
In order to leave comments, you need to log in
Try adding a dollar sign (end of line for matching)
.htaccess setup guide with examples
RewriteCond %{QUERY_STRING} (^|&)name\=Toronto($|&)
RewriteRule ^site\.ru/city$ http://site.ru/city? [L,R=301]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question