Unable to get base urls working

Hi there! Thought I’d ask here first…

I’ve followed the installation videos and have got a semi-usable store working that my customers are using, there’s just one thing… The base urls! In the videos it seems like the easiest thing to do but the grief it has caused made me put it off for another day and launch the store with a url redirect anyways which is what has been working till now.

I use 1and1 hosting for my domain and I honestly have no clue where to start as there’s little troubleshooting about it online, I have tried changing the base url to my own and setting it up as a “frame” in 1and1 where it retains the domain url and shows the the store as well as just a simple redirect. Both of these result in a “connection refused” message with everything being inaccessible till i reset the base Urls in phpmyadmin (you can see why I started to put it off after multiple rounds of this).

This usually woudn’t be an issue but my retail store is growing quite quickly now and I can’t add https secure connections which is obviously far from ideal, especially with a growing userbase…

Can anyone help? (sorry for the rambling)

Hi @Jayy. It sounds like you’ve truly fallen down the rabbit hole on this one. We should be able to bail you out though. You mentioned that your Domain is hosted with 1and1, but is your Web Hosting with them as well? I’ll try and formulate a response based on your answer…

It used to be, however they only support mysql version 1.5 which was fine with magento 1 but in order to update to version 2 I acquired an ubuntu server from a company called Hetzner which now hosts my magento 2 site… Thanks for any help you may be able to provide!

I’m going to make some assumptions on your setup, to create a mental picture. This is hypothetically what your setup should be like to get things pointed in the right place.

1. 1&1 Setting (Domain Name)
Here, you’re telling 1&1 to point to your Web Hosting IP address whenever someone tries to visit example.com

2. Domain Name: example.com
DNS A Record: Name (example.com) | Type (A) | Value (123.123.123.123)

Hetzner (Web Hosting)
Now you’re telling Apache to look out for any connections pointing to itself (both HTTP and HTTPS), then pointing them towards the directory of your web folder.

Web Root Directory: /var/www/html/
Apache Config:

<VirtualHost *:80>
    DocumentRoot "/var/www/html"
    ServerName example.com

    etc etc etc
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot "/var/www/html"
    ServerName example.com

    etc etc etc
</VirtualHost>

3. Magento 2 (Base URLs)
Now you’re simply telling Magento to handle all requests as example.com. Your explanation of you 1&1 setup is concerning though, as this adds a few unknown variables.

Base URL: http://example.com/
Base URL (Secure): https://example.com/

Summary
As you can tell, there are 3 major points of failure here. It shouldn’t be too hard to diagnose.

Notes

  • Can you explain how you’ve implemented your current redirect solution?
  • “setting it up as a “frame” in 1and1” I don’t know what this means. Is this 1&1s term for “URL Masking”?
  • When setting the Base URL and Secure URL via phpMyAdmin, it is essential that you manually clear any caches afterwards. This can be done by running this from the web folder:
    rm -rf var/page_cache var/cache var/generation var/di var/view_preprocessed
  • If you create a simple HTML file with “Hello” written in it and call the file hello.html, are you able to view the file by visiting example.com/hello.html (without using your rewrite workaround).

Apologies for the delay in replying, other aspects of the business have required my attention and I’ve had to get myself vaguely familiar with everything again + getting magento dependancies fixed in order to update to 2.3.0.

1and1
Looking over everything again, my domain’s type ‘A’ record did not point to my store server, instead
it pointed to what I assume is 1and1’s address, that has now been changed!

This is a picture of the redirect tab with an explanation 1and1 has for the ‘frame’ you asked about:

My current config is that it just redirects from the domain to the server address, so if you type in the domain name it changes to the server address in the url field.

Apache Config
Now this is interesting, under sites-available in the apache2 directory there is the .conf file 000-default, after looking at online guides they setup new files titled as the domains used. (Not sure if I am meant to do the same)

I looked into this 000-default.conf and it shows the following:

This file does not contain one for port 443 which is needed for SSL? Do you have any videos showing the configuration of this?

Base URLs
These have been changed back to the default server address until I can be sure it won’t mega-break requiring time i currently don’t really have to fix at the moment, simply because customers are actively using the site which obviously makes this kinda tricky if I can’t get it fixed in time…

Answering unanswered notes

Yep we have been doing this but it still doesn’t fix, we’ve been having to do this when resetting the urls back to the default address in order to regain access to anything through chrome, including both the admin tab and store :frowning:

I’m not sure how to do this in relations to Apache, which I think may be the issue with the base url issue

I can totally relate to that. I had a job like that once, where I was the go-to guy for anything and everything. So, by the time I finished one project, I’d completely forgot how to go back and do the other thing.

1and1
So, based on your experience with 1&1, I figured I’d got buy a domain from them and see what their system is all about… What a terrible experience I had. I never got my activation email and then I locked myself out my account for an hour. I finally got in, and it took me a hot minute to get my head around their platform. Everything seems designed to send you in circles back to one of their own services.

Anyway, I found the DNS Section for the domain I just bought. And yes, the A record contains a placeholder to their own servers.

So, I changed the A records from their default IP (217.160.0.213) to one of my servers (209.97.134.30). This caused the 1and1 domain list to show from “Domain not in use” to the image below:

Just to reiterate - This was the only setting I changed after logging in for the first time (apart from disabling auto-renewal). Everything else is just noise.

On a side-note, I noticed the Default TTL in the DNS settings for each record was set to 1 Hour. Once you’re all done with this, you’ll want to go back and set that to 24 hours. Keeping a short TTL can result in a bit of lag from the server.

Apache Config
The changes you made look good. And yes, your server will not support 443 (SSL/HTTPS) connections until you set it up. These aren’t setup as default, because you are required to setup your SSL Certificate inside the configuration file. Setting up SSL isn’t that complicated, but it’s not something I have time to go over right now.

Luckily, there’s loads of stuff on Google that can help you with this. You just need to install an SSL Certificate (refer to SSL Provider docs) and setup your VirtualHost configuration file for 443 (refer to Google).

It’ll end up looking something close to this:

<VirtualHost *:443>
  ServerName www.example.com
  DocumentRoot /var/www/html

  CustomLog /var/log/apache/www.example.com-access.log combined
  ErrorLog /var/log/apache/www.example.com-error.log

  SSLEngine on
  SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
  SSLHonorCipherOrder On
  SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
  SSLCertificateFile "/location-of-the-certificate-file/example-file.crt"
  SSLCertificateKeyFile "/location-of-the-key-file/example-file.key"
</VirtualHost>

If you try to connect to your server using any form of SSL then you’ll probably get a connection issue.

Base URLs
So, having the Base URLS as your server IP address is a good start to confirm things are working. But as you’ve now updated your 000-default.conf ServerName and ServerAlias to your Domain, you might need to change your Magento Base URLs back to the Domain name now. You’ll just have to make sure you turn off the Force SSL settings in Magento in order for the site to work - Until you’ve setup up the 443 configurations.

Summary

  • If your 1&1 settings are like mine, then they’ll be directing all traffic (who try to visit your domain name) to your web server now.
  • Unless you’ve setup VirtualHost support for 443, then your web server should be sitting there waiting to redirect any traffic 80 it sees coming from your domain name to /var/www/html.
  • If your Magento install Base URLs are set to your domain name and Force SSL is turned off, then this should also be sitting there waiting for Apache to route traffic to it.

Hi Craig, thank you for your reply! It is now redirecting… just too many times as shown below which I have no clue how to fix… Any suggestions? My 1and1 settings are the same as yours but something is looping it so many times it errors out?

Did you check that Magento settings weren’t forcing HTTPS, as this could cause this.

Also, I can’t remember which - But your Magento Base URLs should include (or not include) the “www” prefix. Otherwise that could make you go round in a redirect loop.

Oh, clear you cookies too (or try and visit URL in incognito). Sometimes cookies can give you false-positives.

If none of those work, PM me the URL of your site and I’ll see if I can work out where the redirects are looping. I’ll be around for about 40 mins.