Question

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

Subscribe
Share

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?

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

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

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.

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 ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/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]

Hi Ken,

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

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.

Just an update for clarity:

current situation

  1. User enters http://website.com/folder
  2. automatically redirects to http://www.website.com/folder (or /folder/? can’t tell, it happens too quick)
  3. instantaneously redirects to http://website.com/folder/

desired situation

  1. User enters http://website.com/folder
  2. just goes to http://website.com/folder or http://website.com/folder/

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted