website.com/folder redirects to www then to back non-www
When I go to website.com/folder, my website instantaneously goes to www.website.com/folder (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 website.com/folder/.
The website does not redirect when I simply go to website.com/folder/ (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
desired situation
Also let me mention my website is kensch.com/ratemypennstate
please try to go to kensch.com/ratemypennstate and watch it go to www and back to non-www. It's really annoying.
kensch.com/ratemypennstate/ (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>
ServerName kensch.com
ServerAlias www.kensch.com
ServerAdmin email@email.com(redacted)
DocumentRoot /var/www/kensch.com
ErrorLog ${APACHELOGDIR}/error.log
CustomLog ${APACHELOGDIR}/access.log combined
</VirtualHost>
<Directory /var/www/kensch.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Here is my ../www/kensch.com/.htaccess 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 http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
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?