redirects to www then to back non-www

March 1, 2016 1.2k views
DNS DigitalOcean Ubuntu

When I go to, my website instantaneously goes to (I can't tell if there is a / at the end of the url, because it happens so fast) and then it goes back to

The website does not redirect when I simply go to (with the / at the end).

I followed redirect www to non-www digitalocean guide but it is frustrating that my website goes from non-www to www then back again only for this instance.

Can anyone offer any advice as to how to make my website not do this behavior?

Thank you

  • Just an update for clarity:

    current situation

    1. User enters
    2. automatically redirects to (or /folder/? can't tell, it happens too quick)
    3. instantaneously redirects to

    desired situation

    1. User enters
    2. just goes to or
  • Also let me mention my website is

    please try to go to and watch it go to www and back to non-www. It's really annoying. (with the slash at the end) works fine.

  • Hi Ken,

    What web server software are you using to host your site? What does the config for your site look like?

  • Hey Brook, I appreciate you helping me with this.
    I am running Apache. Can you point me to the config for the information that you need?

    For domain record settings, i have an entry of @ pointing to my server ip address and an entry of www pointing to my server ip address

    Here is what is in this file:
    sudo vi /etc/apache2/sites-enabled/kensch.conf

    <VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHELOGDIR}/error.log
    CustomLog ${APACHELOGDIR}/access.log combined

    <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

    Here is my ../www/ file

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

  • My first blush is that it's related to the rewrite regex - and that there's a case with the trailing / being there or not that is causing this. I'll investigate and get back to you.

  • I really appreciate the help in advance -- and thanks for enabling my comment above!

  • So, the issue as it stands is that is the trailing slash not being included means apache looks for a file, and not a folder - when it finds the folder, it returns the content with the trailing slash, indicating a folder. I'd recommend either having a folder at the link you're sending, or including the trailing slash in links as per this documentation

  • Hi Brook,
    I am confused as to what you mean by following these instructions. I have a folder at the link that I am sending. How do I make it so that my website doesn't redirect from a folder (without slash) to www then to non-www with a slash?

    If my a user forgets a slash at the end shouldn't the website automatically add one, without having to go to www then back to non-www?

1 Answer
Have another answer? Share your knowledge.