A
A
andreyguryev2019-02-25 13:00:17
htaccess
andreyguryev, 2019-02-25 13:00:17

.htaccess - how to make a redirect from a third-level domain name to a second-level domain with the addition of a parameter to the url?

Hello!
How to make a redirect in .htaccess so that when you click on the link: italy.domainname.com/contacts, a redirect is performed to the URL: www.domainname.com/contacts?country=Italy
Thank you very much!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-02-25
@andreyguryev

RewriteCond %{HTTP_HOST} ^(www\.)?italy\.domainname\.com$ [NC]
RewriteRule ^contacts$ http://www.domainname.com/contacts?country=Italy [R=301,L]

Or like this:
RewriteCond %{HTTP_HOST} ^(?:www\.)?+(.+)\.(domainname\.com)$ [NC]
RewriteRule ^(contacts)$ http://www.%2/$1?country=%1 [R=301,L]

Or
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^(?:www\.)?+(.+)\.(domainname\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%2/$1?country=%1 [R=301,L]

V
Viktor Taran, 2019-02-25
@shambler81

RewriteCond %{HTTP_HOST} ^(www.|)(.+[^\.])\.domainname\.com/$
# с ввв и без нее, выделяем во вторую группу домен3 уровня до первой точки.
RewriteRule ^contacts$ https://www.domainname.com/contacts\?country\=%2 [L,R=301]
# не забываем экранировать спец символ \?, равно кстати тоже спец символ \= ( хотя = и так сработает)

At the end, do not forget to mark the issue as resolved, put a tick for the dudes;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question