htaccess redirect for www to non-www not working

This is driving me bananas. For some reason my domain will not work to redirect https-WWW to https-non-WWW. This works with every other permutation except https://www.nextoronto.com

What code do I use in the .htaccess that will allow it to work for all permutations?

Read More

Edit: This is the rewrite code now:

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

Related posts

4 comments

  1. It looks sound, perhaps that rule isn’t being reached due to other rules in front of it?

    Here is what I use that works:

    # Force SSL
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]
    
    # Redirect www to non-www
    RewriteCond %{HTTP_HOST} ^www. [NC]
    RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]
    
    # My other rewrites for routing all requests to index.php go here...
    
  2. Edit the URL and try with this code:

    RewriteEngine on
    rewritecond %{http_host} ^www.example.com [nc]
    rewriteCond %{SERVER_PORT} 80 
    rewriterule ^(.*)$ https://example.com/$1 [r=301,nc]
    
  3. Step 1

    You should make .htaccess file like this

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(.*)$ index.php?url=$1

    Step 2

    Go to the directory, then view mark the option file extension. Then see the .htaccess file.

  4. When no rewrite works, no matter what you do, consider what happened to me. IIS or WAMP, on my laptop, redirected all calls to my domain (call it example.com) to localhost. So creating all the rewrites on my example.com server were to no avail because no calls to example.com ever made it out of my computer. Just do a “ping example.com” and if you get an IP of 127.0.0.1, edit your HOSTS file.

Comments are closed.