Answer the question
In order to leave comments, you need to log in
.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
RewriteCond %{HTTP_HOST} ^(www\.)?italy\.domainname\.com$ [NC]
RewriteRule ^contacts$ http://www.domainname.com/contacts?country=Italy [R=301,L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?+(.+)\.(domainname\.com)$ [NC]
RewriteRule ^(contacts)$ http://www.%2/$1?country=%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^(?:www\.)?+(.+)\.(domainname\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%2/$1?country=%1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.|)(.+[^\.])\.domainname\.com/$
# с ввв и без нее, выделяем во вторую группу домен3 уровня до первой точки.
RewriteRule ^contacts$ https://www.domainname.com/contacts\?country\=%2 [L,R=301]
# не забываем экранировать спец символ \?, равно кстати тоже спец символ \= ( хотя = и так сработает)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question