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

I am using the following code in my httpd.conf for redirections:

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

But, it ends up redirecting to www.domain.com/domain.com//domain.com//domain.com

I want all the following URLs to redirect to domain.com:

http://domain.com
http://www.domain.com
www.domain.com

This should do it. The problem is that it looks pretty much like what you already have. When you type http://domain.com in your browser, does it work? Or does it redirect to somewhere else?

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

Redirect domain.com to www.domain.com and vice versa, You may want to Redirect domain.com to www.domain.com or www.domain.com to domain.com. Find the htaccess rules you can use to do  Creating Your Own Website was Never That Easy. Come and Check it Out!

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

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]

How to redirect from www.domain.com to domain.com?, This should do it. The problem is that it looks pretty much like what you already have. When you type http://domain.com in your browser, does it  Search Domain Availability & Get A Domain Today. Or Transfer Your Website Automatically. We Power More Than 1.2 Million Websites Around The Globe.

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] 

Redirecting Your Domain to www or non-www URL, In this article we explain how to redirect your domain to either the www or non-​www version of it's URL. Creating Your Own Website was Never That Easy. Come and Check it Out!

for SSL Virtual host use the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com
RewriteRule ^(.*)$ https://yourdomain.com$1 [R=301,L]

Full Example below:

<VirtualHost *:443>
    ServerAdmin youname@yourdomain.com
    DocumentRoot "/var/www/html/yourdomain"
    ServerName yourdomain.com
    ServerAlias  www.yourdomain.com *.yourdomain.com
    ErrorLog "logs/yourdomain-error_log"
    CustomLog "logs/yourdomain-access_log" common
    ErrorDocument 404 /index.php
    <Directory "/var/www/html/yourdomain">
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/yourdomain/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/yourdomain/chain.pem
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com
    RewriteRule ^(.*)$ https://yourdomain.com$1 [R=301,L]
</VirtualHost>

What is the process to redirect www.domain.com to domain.com , Update .htaccess with 301 canonical redirects data: > RewriteEngine On RewriteCond %{HTTP_HOST} !^your-site.com$ [NC] RewriteRule ^(. In the left pane, click on.htaccess Editor. Select the domain from the dropdown and then a directory and then click on Use Direct Editor. Add one of the following code snippets into your.htaccess file (based on what you want to do.

[SOLVED] need to redirect http://<domain>.com to http://www , We do this on our Apache webserver but I don't know how to do it on a Windows platform. I need to re-direct the url http://<domain>.com to http://www.<domain>. In this documentation, we can check how to redirect domain.com to www.domain.com and redirect www.domain.com to domain.com. We can do this by adding the rewrite rule in the.htaccess file. (It is also possible to do the same by using cPanel Redirect tool. More details of that method is available here)

How to redirect www.domain.com to domain.com (or reverse), If you are on an Apache webserver, you can use mod_rewrite in order to redirect all traffic that goes to the www.domain to the "non www" domain. (If you want it  Changing an existing domain or subdomain to redirect Navigate to the Manage Domains page. The Manage Domains page opens. Click the Edit button located to the right of the domain/subdomain under the 'Web Hosting' column.

www.domain.com redirects to domain.com/domain.com, were redirecting requests from WWW.domain.com to domain.com/domain.com. The domain that's not redirecting is "www.timkranen.com". So, The Forward Domain Name is easily task for the enable domain redirection to the another or different website by the use of the CPanel from the Domain or Web hosting providers. So Enjoy friends and if you have any doubt then let me know by comment below. Watch the below Video for How to Redirect/Forward Domain Name to a different Website.

Comments
  • It works when I go to domain.com, but it does not work when I go to domain.com or www.domain.com
  • When you to go domain.com it shows your website just fine, but if you go to www.domain.com it does the weird broken URL thing. Did I correctly interpret what you said?
  • Actually, this only happens in Chrome. In Firefox, www.domain.com goes to domain.com//. How come there is an extra slash at the end of the URL?
  • Ah! The extra slash comes from the (.*) match. It matches the opening slash. I've edited my answer above to compensate.
  • Can you provide the domain that you are doing this on so I can see the HTTP headers that are being sent/received?