E
E
Eugene M2019-07-20 07:16:35
htaccess
Eugene M, 2019-07-20 07:16:35

How to redirect correctly with htaccess?

How to record correctly so that when entering without www there is a redirect, such a record only if we enter the site from www works.

RewriteCond %{HTTP_HOST} ^www\.site\.ru [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://m.site.ru/$1 [L,R=302]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-07-20
@hotwind

If you need both options (with www and without).

RewriteCond %{HTTP_HOST} ^(www\.)?site\.ru$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://m.site.ru/$1 [L,R=302]

If you need a rule only for without www.
RewriteCond %{HTTP_HOST} ^site\.ru$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://m.site.ru/$1 [L,R=302]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question