A
A
Alexander Savenko2014-03-19 01:32:52
htaccess
Alexander Savenko, 2014-03-19 01:32:52

How to change domain via .htaccess?

Hello!
For a very long time I can not solve one problem and understand what's wrong.
The point is that I need to redirect requests to one domain like:
example.com → example.ru
example.com/page → example.ru/page
sub.example.com → sub.example.ru
sub.example.com/ test
→ sub.example.ru/test if the domain is not example.ru, then we apply the rules to make the domain the way it should be.
I searched for a long time and even seemed to find a solution, but for some reason it does not work (no redirects occur):
RewriteCond %{HTTP_HOST} !example\.ru$
RewriteCond %{HTTP_HOST} ^([^.]+\. )?example\.
RewriteRule ^ http://%1example.ru%{REQUEST_URI} [NC,L,R=301]
If I comment on the second line, it starts working, but without subdomains.
So far I have settled on my decision:
RewriteCond %{HTTP_HOST} !([^.]+\.)?example.ru$ [NC]
RewriteRule ^ http://example.ru%{REQUEST_URI} [R=301,L]
Please Your help and thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question