F
F
Finx2017-05-22 16:24:11
htaccess
Finx, 2017-05-22 16:24:11

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=TorontoI 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

3 answer(s)
L
Lumore, 2017-05-22
@Lumore

In PHP you can simply:
header('Location: /');

K
Ksush Paparadze, 2017-05-22
@evpanov

Try adding a dollar sign (end of line for matching)
.htaccess setup guide with examples

V
Viktor Taran, 2017-05-24
@shambler81

RewriteCond %{QUERY_STRING} (^|&)name\=Toronto($|&)
RewriteRule ^site\.ru/city$ http://site.ru/city? [L,R=301]

The question at the end will delete the get

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question