J
J
John Freeman2016-02-16 10:52:57
Apache HTTP Server
John Freeman, 2016-02-16 10:52:57

How to make a 301 redirect to www in .htaccess???

Hello everyone, you need to redirect to www only from the domain (for example, I enter site.com and it throws me to www.site.com), but what would the IP open normally (for example, the same site, just open by ip now it throws to www.IP but it should just open IP)
here is the code that I have:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zooks, 2016-02-16
@zooks

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question