M
M
modx10292019-08-05 10:11:22
htaccess
modx1029, 2019-08-05 10:11:22

Redirect from www to http not working?

There is a site. I prescribe:

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

The site.com page opens. But when I enter www.site.com, it doesn't redirect to site.com, but a 404 error pops up.
The fact is that there are a lot of ads on the boards where the site is registered with www. How to make people automatically go to site.com, even if they type www.site.com, but don't get a 404.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
dodo512, 2019-08-05
@dodo512

And there is definitely a 404 error, not a DNS error, and it is not possible to find the address from www.
You need to check if there is an A-record for www in the DNS settings.
And in the web server settings, check if there is a www alias.

A
aglgl, 2019-08-05
@aglgl

Is the rewrite module itself enabled?

V
Vladislav Lyskov, 2019-08-05
@Vlatqa

well, because you didn't write a redirect

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

V
Viktor Taran, 2019-08-05
@shambler81

and protocol
and did not escape special characters

RewriteCond %{HTTP_HOST} !^www\.site\.com$ [NC]
RewriteRule ^(.*)$ https://site.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