Kitz Forum

Internet => Web Hosting & Web Design => Topic started by: Weaver on August 06, 2020, 12:18:41 AM

Title: Webserver redirect from www. to / or the reverse
Post by: Weaver on August 06, 2020, 12:18:41 AM
I’m just setting up a webserver at AA, I’ve emailed them with a few questions. If I try to do an http GET by hand using telnet to port 80, I can get the http response that I want if I include a "www." in the request. Without the www, I get an error response.

When I’ve tackled this kind of things before I used .htaccess and mod_rewrite to redirect www to / or the other way round, I can’t remember. I will ask AA if users are allowed to use .htaccess files.

What do you think is the best way of dealing with the www or nothing issue in general?

AA has a web page dealing with this and giving a solution. However I don’t have a webpage on that webserver; all I have is an http 301 redirect to another domain on a different server and that has been implemented with an index.http and a Location: field as according to AA’s support note. That all works, the redirect, but only if www is specified.

On the DNS server I’ve done a redirect for www. to the same webserver by using a CNAME. But as far as what’s going on without the www, I’m lost.

It’s so long, 15 years ago since I last set this up on a server, so I just can’t remember the details, but the power of .htaccess makes it easy to do anything.
Title: Re: Webserver redirect from www. to / or the reverse
Post by: Alex Atkin UK on August 06, 2020, 12:45:13 AM
The virtual host for your site needs to actually be looking for the domain with and without www, so it depends how its been configured.
eg how mine is configured
Quote
ServerName csdprojects.co.uk
ServerAlias www.csdprojects.co.uk
Title: Re: Webserver redirect from www. to / or the reverse
Post by: Weaver on August 06, 2020, 01:53:53 AM
I think I’ve just solved it. When I FTPed into the server the username I used was "www.example.com" (sic) yes, the same as the domain name for the site. That’s how the virtual server identifies which virtual host you are being, but there’s more - it also controls the directory at which you land and in which you are jailed, so if I log in with username just "example.com" without the www, I appear in a directory one level higher and am looking down upon a directory called www. I never knew this; I was in the www sub directory before and didn’t know it. So it turns out that I have to do the index.http thing in the directory one level higher instead or as well not sure which - not sure yet whether I have to put the same file in the upper level and in the subdir www to get things to work with and without the www. It may be that just the upper level will suffice, or it may be I have to put two copies in place - I could soon test that.
Title: Re: Webserver redirect from www. to / or the reverse
Post by: Alex Atkin UK on August 06, 2020, 06:29:27 AM
Its strange but perhaps its a way for you to be able to easily add sub-domains without them doing more configuration?
Title: Re: Webserver redirect from www. to / or the reverse
Post by: d2d4j on August 06, 2020, 08:19:37 AM
Hi

Sorry you have totally confused me

@weaver - are you using a dedicated server from aa and setting up a web server or is this just a website on an aa webserver

I have no idea what index.http is or perhaps it just another name for a service

If using 2 different ftp credentials and each go to different locations specifically then I would think you have set these credentials up and told them the directory to goto

I would also advice using domain.url and www.domain.url as users is not secure and easily guessed (as is ftp.domain.url), so I would change them

Htaccess - I always believed if you had a htaccess file in root hosting folder, this is global to the hosting folders unless there is another htaccess in a hosting folder, at which point the global htaccess changes to the new htaccess found in the hosting folder

You may also want to review your hosting control panel, as you should be able to change php versions etc...

Many thanks

John
Title: Re: Webserver redirect from www. to / or the reverse
Post by: Chrysalis on August 06, 2020, 12:31:44 PM
now days its standard to have the vhost configuration work with and without www, www subdomain is kind of considered legacy now days.  vhost configuration is something handled by the admin of the server in question (or the control panel if it has one e.g. directadmin or cpanel).

htaccess can work around it with redirects.
Title: Re: Webserver redirect from www. to / or the reverse
Post by: Weaver on August 07, 2020, 03:38:41 AM
> @weaver - are you using a dedicated server from aa and setting up a web server or is this just a website on an aa webserver

It’s the latter, not a dedicated server.