How to redirect from www.domain.com to .com domain?

I use the following code in my httpd.conf to redirect:

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

But he ends up redirecting to www.domain.com/domain.com//domain.com//domain.com

I want all of the following URLs to be redirected to a .com domain:

 http://domain.com http://www.domain.com www.domain.com 
+6
source share
3 answers

That should do it. The problem is that it is very similar to what you already have. When you enter http://domain.com into your browser, will it work? Or is it being redirected to another location?

 RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.domain\.com RewriteRule ^(.*)$ http://domain.com$1 [R=permanent,L] 
+8
source

http://www.webweaver.nu/html-tips/web-redirection.shtml offers

 Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^example\.com RewriteRule (.*) http://example.com/$1 [R=301,L] 
+1
source
 RewriteEngine On # Redirect ANY non-www request to https and www RewriteCond %{HTTP_HOST} !^(www.\.domain\.com)?$ RewriteRule (.*) https://www.domain.com/$1 [R=301,L] # Redirect ANY HTTP request to https and www RewriteCond %{SERVER_PORT} !443 RewriteRule (.*) https://www.domain.com/$1 [R=301,L] 
+1
source

Source: https://habr.com/ru/post/916137/


All Articles